1139. City Blocks
Time Limit: 1.0 second
Memory Limit: 16 MB
Memory Limit: 16 MB
The blocks in the city of Fishburg are of square form. N avenues running south to north and Mstreets running east to west bound them. A helicopter took off in the most southwestern
crossroads and flew along the straight line to the most northeastern crossroads. How many blocks did it fly above?
Note. A block is a square of minimum area (without its borders).
Input
The input contains N and M separated by one or more spaces. 1 < N, M < 32000.
Output
The number of blocks the helicopter flew above.
Samples
| input | output |
|---|---|
4 3 |
4 |
3 3 |
2 |
Hint
The figures for samples:

#include <iostream>
using namespace std;
int main()
{
int n, m, i, ans = 0, x, y;
double k, a, b;
cin>>n>>m;
n--;
m--;
ans = n;
for (i=1; i<=m; i++)
if ((i*n)%m != 0)
ans++;
cout<<ans<<endl;
}
1321

被折叠的 条评论
为什么被折叠?



