uva12169-disgruntled Judge (modulo operation)

Source: Internet
Author: User

If you know a, you can calculate the X2, according to X3= (ax2+b) mod10001 calculate B.
The entire sequence can then be computed in O (T) time.
If a contradiction is found and entered in the calculation, a is illegal because a is an integer of 0~10000, even if all a is enumerated, the time efficiency is high enough.
Enumeration A, using X1,X3 to find B, the relationship between all x can not satisfy a, a, a.

How to find B through a,x1,x3.
x2 = (A * x1 + b)% 10001;
x3 = (A * x2 + b)% 10001;
The 2 formulas of the United State
x3 = (A * (A * x1 + b)% 10001 + b)% 10001;
x3 = (A * (A * x1 + b) + b)% 10001;
So x3 + 10001 * k = A * A * x1 + (A + 1) * b;
X3-a * A * x1 = (A + 1) * b + 10001 * (-K);
So it's a matter of asking for B and K, to satisfy this equation, not to extend the general usage of Euclid?
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < vector> #include <stack> #include <queue> #include <map> #include <set> #include <list> #include <string> #include <cmath> #include <sstream> #include <ctime>using namespace std;# Define _PI ACOs ( -1.0) #define INF 1 << 10#define esp 1e-6typedef long long ll;typedef unsigned long long ull;typedef    pair<int,int> pill; #define MAXD + 10#define max_size 10001void gcd (LL a,ll b,ll &d,ll &x,ll &y) {        if (!b) {d=a;        x=1;y=0;    Return        } else {gcd (b, a%b, D, y, x);        Y-= x * (A/b);    return;    }}int Main () {LL a,b,x[maxd];    int T;    scanf ("%d", &t);    for (int i=1;i<2*t;i+=2) scanf ("%lld", &x[i]); for (a=0;;        a++) {LL k, B, D;        LL t = (x[3]-a*a*x[1]);        GCD (Max_size, a+1, D, K, b);        if (t% d) continue;        b = b * T/D; int Yes = 1; for (int i=2;i<=2*t;i++) {if (i&1) {if (x[i]!= ((a*x[i-1]+b)%max_size)) {y                    es=0;                Break            }} else {x[i]= (a*x[i-1]+b)%max_size;    }} if (yes) break;    } for (int i=2;i<=2*t;i+=2) printf ("%lld\n", X[i]); return 0;}



uva12169-disgruntled Judge (modulo operation)

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.