Revival's odd

来源:互联网 发布:无线传感器网络概念 编辑:程序博客网 时间:2024/06/03 05:45
Revival's odds

时限:1秒 内存:32M 通过:10 提交:27

 

Everyone should be very familiar with Yang Hui Triangle, Yang Hui Triangle is shown as follows:
11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 1......................................
Its general form can be summarized as follows:
  • the n-th line contains n +1 values (begin from line 0)
  • for the k-th value in the n-th line(n>=1)
    • When k = 1 or k = n +1 its value is 1
    • When k! = 1 and k! = n +1 its value is the sum of the k-1th value in the n-1-th line and the k-th value in the n-1-th line
Now, your question is coming, oaiei would like to know the parity of the k-th value in the n-th line and he would like to know the number of odd in the n-th line.

Input

 

There are multiply tests. For each test, there are two integer n(1<=n<=10^9) and k(1<=k<=n+1).

 

Output

 

For each test, you should output two integer x and y, separating by a blank space, x denotes the parity of the k-th value in the n-th line, if the value is odd, you should output “1”, otherwise output “0”. y denotes the number of odd in the n-th line.

 

Sample Input

1 12 2

Sample Output

1 20 2
 
#include<iostream>using namespace std;int odd(int n,int k){    return k==(n&k);}int main(){ int k; long n,sum; while(cin>>n>>k) {   printf("%d ",odd(n,k-1));      sum=1;  while(n>=2)  {   sum*=n%2+1;   n=n/2;  }  if(n>0)   sum*=n+1;  printf("%ld/n",sum);

 

 }  return 0;}

 

好险,时间居然是0.98s,差一点点,呵呵

原创粉丝点击