SICIly 2501
2012-07-14 16:00
288 查看
OJ
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> #include <map> #include <set> #include <string> #include <cstring> #include <list> #include <queue> #include <stack> #include <cmath> //#include <time.h> //#include <fstream> using namespace std; #define PF(x) (scanf("%d",&x)) #define PT(x,y) (scanf("%d%d",&x,&y)) #define PR(x) (printf("%d\n",x)) #define PRT(x,y)(printf("%d %d\n",x,y)) #define M 9901 int n,k; typedef long long LL; LL Mod(int ns,int ks) { if(ks==1) return (LL)ns%M; if(ks==0) return (LL)1; if(ks%2) {LL a = Mod(ns,ks/2);return a*(LL)ns%M*a%M;} LL a = Mod(ns,ks/2); return a*a%M; } LL ans(int ns,int ks) { if(ks==1) return (LL)ns%M; if(ks==0) return (LL)0; if(ks%2) { int v = ks/2; LL an = ans(ns,v); LL anh = ans(ns,v+1); return (an+anh*Mod(ns,v)%M)%M; } int v = ks/2; LL an = ans(ns,v); return (an+Mod(ns,v)*an%M)%M; } void init() { while(scanf("%d%d",&n,&k)!=EOF) { printf("%lld\n",ans(n%M,k)%M); } return ; } int main() { init(); return 0; }
相关文章推荐
- Sicily 2501. 算算式
- Sicily 2501.算算式
- Sicily 2501. 算算式
- sicily2501
- Sicily 2501 算算式
- sicily 2501. 算算式
- Sicily 2501. 算算式
- sicily 1500. Prime Gap
- sicily 1308. Dependencies among J
- Sicily1099-Packing Passengers-拓展欧几里德算法
- Sicily 1692. Cover Constraints
- Sicily 1790. Single Round Match
- Sicily 13476. 完数问题
- Sicily 1047 Super Snooker
- hdu--2501--Tiling_easy version
- <OJ_Sicily>1134积木分发
- <OJ_Sicily>Can I Post the letter
- Sicily1201——01000001
- <OJ_Sicily>数字反转
- <OJ_Sicily>Threecolor Problem