HDOJ 2769 Disgruntled Judge extension GCD

Source: Internet
Author: User

HDOJ 2769 Disgruntled Judge extension GCD


Extended GCD:

Enumerate a, extend GCD for B, and then perform a brute force check.

Disgruntled Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 329 Accepted Submission (s): 142


Problem DescriptionOnce upon a time, there was an nwerc judge with a tendency to create slightly too hard problems. as a result, his problems were never solved. as you can image, this made our judge somewhat frustrated. this year, this frustration has culminated, and he has decided that rather than spending a lot of time constructing a well-crafted problem, he will simply write some insanely hard p Roblem statement and just generate some random input and output files. After all, why bother having proper test data if nobody is going to try the problem anyway?

Thus, the judge generates a testcase by simply letting the input be a random number, and letting the output be another random number. formally, to generate the data set with T test cases, the judge generates 2 T random numbers x1 ,..., x2T between 0 and 10000, and then writes T, followed by the sequence x1, x3, x5 ,..., x2T-1 to the input file, and the sequence x2, x4, x6 ,..., x2T to the output file.

The random number generator the judge uses is quite simple. he picks three numbers x1, a, and B between 0 and 10000 (random SIVE), and then for I from 2 to 2 T lets xi = (a · XI-1 + B) mod 10001.

You may have thought that such a poorly designed problem wocould not be used in a contest of such high standards as nwerc. Well, you were wrong.
InputOn the first line one positive number: the number of testcases, at most 100. After that per testcase:

* One line containing an integer n (0 ≤ n ≤10000): an input testcase.

The input file is guaranteed to be generated by the process described above.
OutputPer testcase:

* One line with an integer giving the answer for the testcase.

If there is more than one output file consistent with the input file, any one of these is acceptable.
Sample Input
3178223014

Sample Output
972719184110

SourceNWERC 2008


#include 
 
  #include 
  
   #include 
   
    #include using namespace std;typedef long long int LL;const int mod=10001;LL s[mod+100],n;void ex_gcd(LL a,LL b,LL& d,LL& x,LL& y){    if(!b)    {        d=a;x=1;y=0;    }    else    {        ex_gcd(b,a%b,d,y,x);        y-=a/b*x;    }}int main(){    while(cin>>n)    {        n*=2;        for(int i=1;i<=n;i+=2) cin>>s[i];        for(int a=0;a<=10000;a++)        {            LL b,k,d;            LL t=s[3]-a*a*s[1];            ex_gcd(a+1,-mod,d,b,k);            if(t%d) continue;            b=b*t/d;            bool flag=true;            for(int i=2;i<=n;i++)            {                LL temp=(s[i-1]*a+b)%mod;                if(i%2==1)                {                    if(temp!=s[i])                    {                        flag=false; break;                    }                }                else s[i]=temp;            }            if(flag==true)            {                for(int i=2;i<=n;i+=2)                {                    cout<
    
     


Related Article

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.