标签:des style blog http color java os io strong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 443 Accepted Submission(s): 255
1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5 #include<queue> 6 #include<stack> 7 #include<set> 8 #include<algorithm> 9 #include<cstring> 10 #include<stdlib.h> 11 #include<math.h> 12 #include<map> 13 using namespace std; 14 #define ll long long 15 int sg[1000],k; 16 void getsg(){ 17 18 for(int i=1;i<=100;i++){ 19 int vit[1000]; 20 memset(vit,0,sizeof(vit)); 21 for(int j=1;j<=i;j*=k) vit[sg[i-j] ]=1; 22 for(int j=0;;j++) 23 if(!vit[j]){ 24 sg[i]=j;break; 25 } 26 } 27 } 28 int fix(int x,int len){ 29 if(((x%len)==0)||(((x%len)%2==0)&&(x%len!=len-1))) return 1; 30 else return 0; 31 } 32 int main(){ 33 int t,s;cin>>t; 34 while(t--){ 35 cin>>s>>k; 36 if(k&1){ 37 if(s&1) cout<<1<<endl; 38 else cout<<0<<endl; 39 continue; 40 } 41 int len=2*(k/2-1)+3; 42 ll tmp=1; 43 if(fix(s,len)){ 44 cout<<0<<endl; 45 continue; 46 } 47 while(1){ 48 ll kk=s-tmp; 49 kk%=len; 50 if(fix(kk,len)){ 51 cout<<tmp<<endl; 52 break; 53 } 54 tmp*=k; 55 } 56 } 57 }
标签:des style blog http color java os io strong
原文地址:http://www.cnblogs.com/ainixu1314/p/3934935.html