参考:http://www.cnblogs.com/naturepengchen/articles/3952145.html
#include<stdio.h> #include<string.h> #include<time.h> const int N=3e7+11; int ans[N]; int gcd(int a,int b){ if(!b) return a; return gcd(b,a%b); } void init(){ for(int c=1;c<=N/2;c++){ for(int a=c+c;a<N;a+=c){ int b=a-c; if((a^b)==c) ans[a]++; } } for(int i=2;i<N;i++) ans[i]+=ans[i-1]; } int main(){ init(); int t,cas=0,n; scanf("%d",&t); while(t--){ scanf("%d",&n); printf("Case %d: %d\n",++cas,ans[n]); } return 0; }
原文:http://www.cnblogs.com/L-King/p/5758368.html