zoj 4005 Lucky Man 大数开根号

Lucky Man

Time Limit: 2 Seconds       Memory Limit: 65536 KB

BaoBao is keen on collection. Recently he is abandoning himself to Kantai Collection, especially to collecting cute girls, known as "Fleet Girls".

There are  various types of girls in the game. To get a girl, one can use some materials to build her. The probability to get a type of girl by building is the same for all types of girls. From the Coupon Collector's Problem we know that, to collect all types of girls, the expected number of times of building is .

But this rule does not apply to BaoBao, as he is always luckier than the ordinary players (maybe because he's an European). For BaoBao to collect all types of girls, the expected number of times of building is , where  means the maximum integer that doesn't exceed .

As a lucky man, BaoBao is not interested in the actual value of , and he just wants to know whether  is odd or even. Can you help him?

Input

The first line of the input is an interger  (about 100), indicating the number of test cases. For each test case:

The first line contains an integer  (), indicating the number of types of girls.

Output

For each test case, if  is odd output "1" (without quotes), if  is even output "0" (without quotes).

Sample Input
9
2
3
23
233
2333
23333
233333
2333333
23333333
Sample Output
1
1
0
1
0
0
1
1
0
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int l;char ans[1000];int num=0;
int work(int o,char *O,int I)
{
    char c,*D=O;
    if(o>0)
    {
        for(l=0;D[l];D[l++]-=10)
        {
            D[l++]-=120;
            D[l]-=110;
            while(!work(0,O,l))
                D[l]+=20;
            //putchar((D[l]+1032)/20);
            ans[num++]=(D[l]+1032)/20;
        }
        //putchar(10);
        //ans[num++]='1';ans[num++]='0';
    }
    else
    {
        c=o+(D[I]+82)%10-(I>l/2)*(D[I-l+I]+72)/10-9;
        D[I]+=I<0 ? 0 : !(o=work(c/10,O,I-1))*((c+999)%10-(D[I]+92)%10);
    }
    return o;
}

int main()
{
    char s[1200];
    int t;scanf("%d",&t);
    while(t--){
    	num=0;
	s[0]='0';
    scanf("%s",s+1);
    if(strlen(s)%2 == 1)
        work(2,s+1,0);
    else
        work(2,s,0);
    ans[num]='\0';
    //printf("%s\n",ans);
    int tmp=ans[num-1]-'0';
    if(tmp&1) printf("1\n");
	else printf("0\n"); 
	}
    return 0;
}

  python好像更快,cls的题解存下:

 http://www.cnblogs.com/clrs97/p/8541379.html 题解 
 

转载于:https://www.cnblogs.com/vainglory/p/8549201.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值