51nod 1831:小C的游戏

51nod 1831:小C的游戏

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

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

暴力

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

代码如下:

 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 }

 

posted @ 2017-05-19 23:41  barriery  阅读(346)  评论(0编辑  收藏  举报