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 theCoupon 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
110100110
def sqrt(n):
l=1
r=n
while(l<=r):
mid=(l+r)>>1
F=mid*mid //这里要先储存起来,不然在if里面乘的话会更耗时间
if F < n:
l=mid+1
elif F > n:
r=mid-1;
else:
return mid
return r
t=int(raw_input())
for i in range(t):
n=int(input())
if(n==0):
print(0)
continue
r=sqrt(n)
print(int(r&1))
这里贴一个T 的java代码,做模板
package zojmonth;
import java.math.*;
import java.util.*;
public class Main {
public static BigInteger myBigNumSqrt(BigInteger xx)
{
BigDecimal x=new BigDecimal(xx);
BigDecimal n1=BigDecimal.ONE;
BigDecimal ans=BigDecimal.ZERO;
//int i=1;
while((n1.multiply(n1).subtract(x)).abs().compareTo(BigDecimal.valueOf(0.001))==1)
{
//System.out.println(i+"..."+n1);
//i++;
BigDecimal s1=x.divide(n1,2000,BigDecimal.ROUND_HALF_UP);
BigDecimal s2=n1.add(s1);
n1=s2.divide(BigDecimal.valueOf(2),2000,BigDecimal.ROUND_HALF_UP);
}
ans=n1;
//System.out.println(ans);
BigInteger rt =new BigInteger(ans.toString().split("\\.")[0]);
return rt;
}
public static void main (String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int k=0;k<t;k++)
{
BigInteger n=sc.nextBigInteger();
if(n.compareTo(BigInteger.ONE)==0)
{
System.out.println(0);
continue;
}
BigInteger tmp=myBigNumSqrt(n);
//System.out.println(tmp);
if(tmp.remainder(BigInteger.valueOf(2)).compareTo(BigInteger.ONE)==0) //大数取模
{
System.out.println(1);
}
else
{
System.out.println(0);
}
}
}
}