Problem E. exponial---urozero Autumn Training Camp 2016-day 1| | Exponential power-down formula

Source: Internet
Author: User

Title Description:


Post an official tip:


The topic idea, uses the exponential power-down formula to do, notice opens long long.

Code Reference @w4k3up @ Xuhang

thanks to @qq_36704031, the previous code does have a problem, thank the brother for pointing out my mistake.

AC Code: (Corrected)

/* Urozero Autumn Training Camp Day 1:ncpc-2016, Friday, November, Problem E. exponial September 3, 2017 14:21:27 201 7 October 5 13:18 Correct the power-down formula for AC index */#include <iostream> #include <map> #include <set> #include <string&gt
; #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #include <queue
> #include <vector> using namespace std;

typedef long Long LL;

ll N,m,ans;
     ll Euler (ll N) {//return Euler (n) ll Res=n,a=n; for (ll i=2;i*i<=a;i++) {if (a%i==0) {res=res/i* (i-1);//Division first to prevent overflow of intermediate data while (a%i==0
         ) A/=i;
     }} if (a>1) res=res/a* (A-1);
return res;
    } ll Fast_mod (ll x,ll n,ll Max) {ll res=1;
        while (n>0) {if (n & 1) res= (res*x)%max;
        x= (x*x)%max;
    n >>= 1;
} return res;
    } ll func (ll n,ll m) {if (m==1) return 0;
    if (n==1) return 1;
    else if (n==2) return 2%m; else IF (n==3) return 9%m;
else if (n==4) return Fast_mod (4,9,M);

		/* if (n<=4) {ll ans=1;
		for (int i=1;i<=n;i++) {ans=fast_mod (i,ans,m);

	} return ans;
		} */else{ll Phi=euler (m);
		ll Z=func (N-1,phi);
	Ans=fast_mod (N,PHI+Z,M);


} return ans;
	} void Solve () {scanf ("%lld%lld", &n,&m);
printf ("%lld\n", Func (n,m));

	} int main () {solve ();
return 0;
 }


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.