基于分治的思想:
例题:https://www.acwing.com/problem/content/99/
模板:
求num^0+num^1+...+num^k
const int MOD=9901; int QuickExp(int base,int exp) { base%=MOD; int res=1; while(exp) { if(exp&1) { res*=base; res%=MOD; } base*=base; base%=MOD; exp>>=1; } return res; } int Sum(int num,int k) { if(k==0) return 1; if(k%2) { return (1+QuickExp(num,k/2+1))*Sum(num,k/2)%MOD; } else { return (1+num*Sum(num,k-1))%MOD; } }View Code
标签:等比数列,int,num,逆元,exp,return,AcWing,base,MOD From: https://www.cnblogs.com/ydUESTC/p/16794677.html