您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: