ZJNU-B - Diagonal Cut
题意&思路:
给你M×N小块的巧克力,从左上角到右下角切一刀,求有多少格巧克力被分成面积相等的两小块。
设g=__gcd(N,M)
可得直线方程:y=-(M/g)/(N/g)x+N,可以得到x=((N/g)*i)/2,i为奇数。化简得0<i<2*g,又i为奇数得i有g个。
又可以把M×N分成g个,只有当M/g和N/g同时为奇数的时候,成立的点才会在小块的中间,否则只会存在于边上,即为0。
代码:
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
#define cl(x,y) memset(x,y,sizeof(x))
#define ct cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
const int N=1e6+10;
const int mod=1e7+9;
const int maxn=0x3f3f3f3f;
const int minn=0xc0c0c0c0;
const int inf=99999999;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll a,b;
cin>>a>>b;
ll g=__gcd(a,b);
a/=g;
b/=g;
if(a%2==1 && b%2==1)
cout<<g<<endl;
else
cout<<0<<endl;
return 0;
}