poj 2115

it2022-05-23  70

注意2^32用long long其他没坑,扩展欧几里得,,,反正我没想到

#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; typedef long long ll; ll aa,bb,cc,k; void hh(ll a,ll b,ll &d,ll &x,ll &y) { if(!b) { x=1;y=0;d=a; } else { hh(b,a%b,d,y,x); y-=x*(a/b); } } int main() { while(~scanf("%lld%lld%lld%lld",&aa,&bb,&cc,&k)&&(aa||bb||cc||k)) { ll c=bb-aa; ll a=cc; ll b=(ll)1<<k;//注意折了ll的转化 ll d,x,y; hh(a,b,d,x,y); if(c%d) printf("FOREVER\n"); else { c=c/d; b=b/d; printf("%lld\n",(x%b*c%b+b)%b); } } return 0; }

 

转载于:https://www.cnblogs.com/Wangwanxiang/p/6888305.html

相关资源:数据结构—成绩单生成器

最新回复(0)