51nod 1831:小C的游戏

51nod 1831:小C的游戏html

题目连接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1831spa

题目大意:有堆大小为$n$的石子,每人每次能够从中取走一个或留下$d$($d|n$,$d$不为$1$或$n$)个石子,最后一个取石子的为输.code

暴力htm

注意$n=0$时也为输,复杂度$O($可过$)$(滑稽.blog

代码以下:游戏

 1 #include <cstdio>
 2 using namespace std;
 3 typedef long long ll;
 4 ll T,n;
 5 bool jg(ll n){
 6     if(n<=1)return 0;
 7     if(n==2)return 1;
 8     for(ll i=2;i*i<=n;++i)if(n%i==0){
 9         if(!jg(i))return 1;
10         if(!jg(n/i))return 1;
11     }
12     return !jg(n-1);
13 }
14 int main(void){
15     scanf("%lld",&T);
16     while(T--){
17         scanf("%lld",&n);
18         if(jg(n))printf("TAK\n");
19         else printf("NIE\n");
20     }
21 }
相关文章
相关标签/搜索