Hdu-2685i won ' t tell you this is about number theory (number theory)

Source: Internet
Author: User

Topic Links:

I won ' t tell you that this is about number theory problem DescriptionTo think of a beautiful problem description was so hard for me the Let ' s just drop them off. :)
Given four integers A,m,n,k,and s = gcd (a^m-1,a^n-1)%k,calculate the S.

InputThe first line contain a t,then t cases followed.
Each case contain four integers a,m,n,k (1<=a,m,n,k<=10000).

OutputOne line with a integer S.

Sample Input11 1 1 1

Sample Output0 Test Instructions: The value of GCD (a^m-1,a^n-1)%k is obtained; Ideas: There is theorem gcd (a^m-b^m,a^n-b^n) =a^gcd (n,m)-B^GCD (n,m); so gcd (a^m-1,a^n-1)%k = = (A^GCD (n,m)-1)%k; AC Code
#include <bits/stdc++.h>using namespaceStd;typedefLong LongLL;//const LL mod=1e9+7;Const intn=1e5+6;intgcdintXinty) {        if(Y = =0)returnx; returnGCD (y,x%y);}intFastpow (intXintYintz) {    ints =1,Base=x;  while(y) {if(y&1) {s*=Base; S%=Z; }        Base*=Base; Base%=Z; Y= (y>>1); }    returns;}intFunintXintYintZintMoD) {    inttemp =gcd (y, z); return(Fastpow (X,temp,mod)-1+MOD)%MoD;}intMain () {intT; scanf ("%d",&t); inta,n,m,k;  while(T--) {scanf ("%d%d%d%d",&a,&n,&m,&k); printf ("%d\n", Fun (A, n, M, k)); }    return 0;}

Hdu-2685i won ' t tell you this is about number theory (number theory)

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.