POJ 2115 C Looooops
生活随笔
收集整理的這篇文章主要介紹了
POJ 2115 C Looooops
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
被虐得很慘的一道題,WA了無數次,根據題意推出?C?*?x?+?(2?^?k)?*?y?=?B?-?A,用拓展歐幾里德求出x的最小值。如果無解則是死循環!
?
/*Accepted 164K 0MS C++ 882B 2012-07-19 12:03:12*/#include<cstdio> #include<cstring> #include<cstdlib> #define LL long longLL extgcd( LL a, LL b, LL &x, LL &y) {if( b == 0) { x = 1; y = 0; return a;}LL d = extgcd( b, a % b, x, y);LL t = x;x = y;y = t - a / b * y;return d; }int main() {LL a, b, c, e, n;int k;LL x, y;while( scanf("%lld%lld%lld%d", &a, &b, &c, &k) == 4){if( a == 0 && b == 0 && c == 0 && k == 0)break;n = 1LL << k ;e = extgcd( c, n, x, y);LL t = b - a ;if( t % e != 0){printf( "FOREVER\n");}else{x = t / e * x; // x = ((t / e) * x) % n + nx = ( x % (n / e) + (n / e)) % (n / e); //x = x % (n / e);printf( "%lld\n", x) ;}}return 0; }?
?
?
?
轉載于:https://www.cnblogs.com/Yu2012/archive/2012/07/19/2599039.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的POJ 2115 C Looooops的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: delphi中combobox键值对
- 下一篇: form表单获取input对象浏览器区别