GCD XOR
Given an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where
1 B A N.
Here gcd(A; B) means the greatest common divisor of the numbers A and B. And A xor B is the
value of the bitwise xor operation on the binary representation of A and B.
Input
The rst line of the input contains an integer T (T 10000) denoting the number of test cases. The
following T lines contain an integer N (1 N 30000000).
Output
For each test case, print the case number rst in the format, `Case X:' (here, X is the serial of the
input) followed by a space and then the answer for that case. There is no new-line between cases.
Explanation
Sample 1: For N = 7, there are four valid pairs: (3, 2), (5, 4), (6, 4) and (7, 6).
Sample Input
2
7
20000000
Sample Output
Case 1: 4
Case 2: 34866117

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int ans[]={};
void init()
{
int i,j;
for(i=;i<;i++)
{
for(j=i+i;j<;j+=i)
if((j^(j-i))==i)ans[j]++;
}
for(i=;i<;i++)ans[i]+=ans[i-];
}
int main()
{
int t,i,n;
init();
scanf("%d",&t);
for(i=;i<=t;i++)
{
scanf("%d",&n);
printf("Case %d: %d\n",i,ans[n]);
}
}

GCD XOR uvalive6657的更多相关文章

  1. uval 6657 GCD XOR

    GCD XORGiven an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where1 ...

  2. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  3. GCD XOR UVA 12716 找规律 给定一个n,找多少对(a,b)满足1<=b<=a<=n,gcd(a,b)=a^b;

    /** 题目:GCD XOR UVA 12716 链接:https://vjudge.net/problem/UVA-12716 题意:给定一个n,找多少对(a,b)满足1<=b<=a&l ...

  4. UVa 12716 (GCD == XOR) GCD XOR

    题意: 问整数n以内,有多少对整数a.b满足(1≤b≤a)且gcd(a, b) = xor(a, b) 分析: gcd和xor看起来风马牛不相及的运算,居然有一个比较"神奇"的结论 ...

  5. uvalive 6657 GCD XOR

    //感觉太长时间没做题 好多基本的能力都丧失了(>_<) 首先大概是这样的,因为gcd(a,b)=c,所以a,b都是c的倍数,所以我们依次枚举a的值为2c 3c 4c......,a xo ...

  6. GCD XOR(UVa 12716)

    题意:输入整数n(1<=n<=30000000),有多少对整数(a,b)满足1<=b<=a<=n,且gcd(a,b)=a xor b. 题解:设c=gcd(a,b),因为 ...

  7. UVa 12716 - GCD XOR(筛法 + 找规律)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVA 12716 GCD XOR

    https://vjudge.net/problem/UVA-12716 求有多少对整数(a,b)满足:1<=b<=a<=n,且gcd(a,b)=a XOR b 结论:若gcd(a, ...

  9. UVA 12716 GCD XOR (异或)

    题意:求出[1,n]中满足gcd(a,b)=a xor b,且1<=a<=b<=n的对数 题解:首先a xor b = c,则a xor c = b,而b是a的约数,则可以使用素数筛 ...

随机推荐

  1. Django 后台支持中文方法

    今天遇到的一个问题,mark一下: django后台可以支持中文界面,一开始一直纠结于settings.py 中 LANGUAGE_CODE = 'en-us'中的'en-us'该更改成什么.zh-c ...

  2. 打造基于Clang LibTooling的iOS自动打点系统CLAS(三)

    1. 源码变换 第一章我们提到过,CLAS的本质是对源码做一次非常简单的变换(有些文章里称作变形),即Source-Source-Transformation,将打点代码精确地插入到目标函数的首部,保 ...

  3. 使用javaconfig配置freemarker

    package com.yy.config; import org.springframework.context.annotation.Bean; import org.springframewor ...

  4. hover用法实例

    //hover,鼠标移入移出的另一种用法 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" &qu ...

  5. Spring中ApplicationContextAware的用法

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt379 一.这个接口有什么用? 当一个类实现了这个接口(Application ...

  6. Linux-chown命令(1)

    chown  [chang owner]:更改文件的属主,也就是指定文件的拥有者改为另一个指定的用户或组. 命令格式: chown [选项]... [用户][:[组]] 文件... 例子:  sudo ...

  7. asp.net mvc 4 项目升级到 asp.net mvc5

    一.开始 1.打开或新建asp.net mvc 4项目 2.修改 global.asax文件 原: WebApiConfig.Register(GlobalConfiguration.Configur ...

  8. VB与C#语言部分不用的地方Part1

    1. 数据类型: ① 日期型(Date)      表示日期和时间用两个“#”符号把日期和时间的值括起来,如:#08/20/2001#.#2001-08-20#. ② 变体型(Variant)    ...

  9. MySQL索引实战经验总结

    MySQL索引对数据检索的性能至关重要,盲目的增加索引不仅不能带来性能的提升,反而会消耗更多的额外资源,本篇总结了一些MySQL索引实战经验. 索引是用于快速查找记录的一种数据结构.索引就像是数据库中 ...

  10. 团队作业1——团队展示&博客作业查重系统

    团队展示: 1.队名:六个核桃 2.队员学号: 王婧(201421123065).柯怡芳(201421123067组长).陈艺菡(201421123068). 钱惠(201421123071).尼玛( ...