题解:P13365 [GCJ 2011 #1A] FreeCell Statistics
xtzhangziche
·
·
题解
题目传送门
思路
我们需要判断是否存在满足条件的 D 和 G,使得:
Broken 的情况,直接排除以下不可能的情况:
求最小 D 的方法。
我们需要找到最小的 D 使得 D \times P_D \equiv 0 \pmod{100}。
设 g = \gcd(P_D, 100)。
设 k 和 m。
分解:
$g \times m = 100$。
其中 $\gcd(k, m) = 1$($k$ 和 $m$ 互质)。
最小 $D$ 必须满足 $D \times k \equiv 0 \pmod{m}$。
因为 $\gcd(k, m) = 1$,所以 $D$ 必须是 $m$ 的倍数。
因此,最小 $D = m = \dfrac{100}{g}$。
若 $P_G = 0$ 且 $P_D > 0$,或 $P_G = 100$ 且 $P_D < 100$,或 $\dfrac{100}{\gcd(P_D, 100)} > N$,则输出 `Broken`。
否则输出 `Possible`。
## Code
```cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,t;
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>T;
while(T--)
{
int n,pd,pg;
cin>>n>>pd>>pg;
int d=100/__gcd(pd,100ll);
cout<<"Case #"<<++t<<": ";
if((pg==0&&pd>0)||(pg==100&&pd<100)||(d>n)) cout<<"Broken";
else cout<<"Possible";
cout<<'\n';
}
return 0;
}
```