Codeforces Round #198 (Div. 2) —— A
最水的题,可惜当时赶时间没有注意数据范围;暴力超时了!
其实应该用x,y的最大公约数来判断;
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 using namespace std; 3 int gcd(int a,int b) 4 { 5 return b==0?a:gcd(b,a%b); 6 } 7 int main() 8 { 9 int x,y,a,b; 10 cin>>x>>y>>a>>b; 11 if(x<y) 12 { 13 x=x^y; 14 y=x^y; 15 x=x^y; 16 } 17 int k=x/gcd(x,y)*y; 18 cout<<b/k-(a-1)/k<<endl; 19 return 0; 20 }