luogu P1869 愚蠢的组合数(质因数+瞎搞)

题意

n<=105

题解

一个数是不是偶数就是看有没有二这个质因子。

所以我们先预处理每个数的阶乘的二这个质因子的数量

然后按公式判断就行了。

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<cstdio>
 5 #include<algorithm>
 6 using namespace std;
 7 int t,a,b,cnt[300000];
 8 int main(){
 9     scanf("%d",&t);
10     for(int i=1;i<=200000;i++){
11         int j=i;cnt[i]=cnt[i-1];
12         while(j%2==0&&j){
13             j/=2;cnt[i]++;
14         }
15     }
16     while(t--){
17         scanf("%d%d",&a,&b);
18         if(cnt[b]+cnt[a-b]==cnt[a])printf("1\n");
19         else printf("0\n");
20     }
21     return 0;
22 }

 

posted @ 2018-08-31 15:32  Xu-daxia  阅读(211)  评论(0编辑  收藏  举报