POJ 2115 simple equation solving with modulo

Source: Internet
Author: User

A simple extension of Euclid's question

Here 2^k can not be clever with 1<<k to write, K >= 31 o'clock exploded int, even if defined as long long can not directly write this

Later honestly for (int i=1; i<=k; i++) bb = bb*2; It's over. = =

1#include <cstdio>2#include <cstring>3 4 using namespacestd;5 #definell Long Long6ll EX_GCD (ll A, ll &x, LL B, LL &y)7 {8     if(b = =0){9x =1, y =0;Ten         returnA; One     } All ans = EX_GCD (b, X, a%b, y); -     intt =x; -x = y, y = t-a/b*y; the     returnans; - } - intMain () - { +    //freopen ("a.in", "R", stdin); -     intA, B, C, K; +      while(SCANF ("%d%d%d%d", &a, &b, &c, &k)) { A         if(A = =0&& b = =0&& c = =0&& k = =0) Break; atll aa = c, bb =1, CC = bA, x, y; -          for(intI=1; I<=k; i++) BB = bb*2; -ll g =EX_GCD (aa, X, BB, y); -         if(cc% G! =0){ -Puts"FOREVER"); -             Continue; in         } -ll KK = CC/G; toX*=KK, y*=KK; +Aa/=g, bb/=G; -         if(x >=0) thex = x-x/bb*BB; *         Else $x = x-x/bb*bb+BB;Panax Notoginsengprintf"%i64d\n", x); -     } the     return 0; +}

POJ 2115 simple equation solving with modulo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.