POJ1995 Raising Modulo Numbers (Fast power)

Source: Internet
Author: User

POJ1995 Raising Modulo Numbers

Calculations (A1B1+A2B2+ ... +AHBH)mod M .

Fast power, set of templates

  

/** created:2016 March 30 23:01 45 Second Wednesday * author:akrusher**/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctime>#include<iostream>#include<algorithm>#include<string>#include<vector>#include<deque>#include<list>#include<Set>#include<map>#include<stack>#include<queue>#include<numeric>#include<iomanip>#include<bitset>#include<sstream>#include<fstream>using namespacestd;#defineRep (i,a,n) for (int i=a;i<n;i++)#definePer (i,a,n) for (int i=n-1;i>=a;i--)#defineIn (n) scanf ("%d",& (n))#defineIn2 (X1,X2) scanf ("%d%d",& (x1),& (x2))#defineINLL (n) scanf ("%i64d",& (n))#defineInll2 (X1,X2) scanf ("%i64d%i64d",& (x1),& (x2))#defineINLLD (n) scanf ("%lld",& (n))#defineInlld2 (X1,X2) scanf ("%lld%lld",& (x1),& (x2))#defineINF (n) scanf ("%f",& (n))#defineInf2 (X1,X2) scanf ("%f%f",& (x1),& (x2))#defineINLF (n) scanf ("%lf",& (n))#defineINLF2 (X1,X2) scanf ("%lf%lf",& (x1),& (x2))#defineInc (STR) scanf ("%c",& (str))#defineINS (str) scanf ("%s", (str))#defineOut (x) printf ("%d\n", (x))#defineOut2 (x1,x2) printf ("%d%d\n", (x1), (x2))#defineOutf (x) printf ("%f\n", (x))#defineOUTLF (x) printf ("%lf\n", (x))#defineOUTLF2 (x1,x2) printf ("%lf%lf\n", (x1), (x2));#defineOUTLL (x) printf ("%i64d\n", (x))#defineOUTLLD (x) printf ("%lld\n", (x))#defineOUTC (str) printf ("%c\n", (str))#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#defineSZ (x) ((int) (x). Size ())#defineMem (x, y) memset (x,y,sizeof (×));typedef vector<int>Vec;typedefLong LongLl;typedef pair<int,int>P;Const intdx[4]={1,0,-1,0},dy[4]={0,1,0,-1};Const intinf=0x3f3f3f3f; ll Mod;ll Powmod (ll A,ll b) {ll res=1; a%=mod; for(; b;b>>=1){if(b&1) Res=res*a%mod;a=a*a%mod;}returnRes;}//Fast Power calculationConst BOOLAc=true;intMain () {intT,n;    ll Ans,a,b; inch(t);//don't forget to type in     while(t--) {inlld (mod); inch(n); Ans=0; Rep (I,0, N)    {Inlld2 (A, b); Ans= (Ans+powmod (b))%MoD;    } outlld (ANS); }    return 0;}

POJ1995 Raising Modulo Numbers (Fast power)

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.