• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
L&King
有何不可!
   首页    新随笔    联系   管理    订阅  订阅

UVA 12716 GCD XOR【异或】

参考: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;
}

 

posted @ 2016-08-10 20:48  L&King  阅读(235)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3