题意: 问 gcd(i,j) = i ^ j  的对数(j <=i <= N ) N的范围为30000000,有10000组例子

思路:GCD(a,b) = a^b = c

GCD(a/c,b/c) = 1 (1)

(a-b) <= c (2)

(a/c-b/c) <=1 (3)

(1)(3) => a/c-b/c = 1=> a-b=c

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
const int maxn = 30000000+10;
typedef long long LL;
int N;
int ret[maxn]; void init() {
for(int i = 3; i < maxn; i+=2) ret[i] = 1;
for(int i = 2; i < maxn/2; i++) {
for(int j = i+i; j < maxn; j += i) {
int k = j-i;
if( (k^j) == i){
ret[j]++;
}
}
}
for(int i = 1; i < maxn; i++) ret[i] += ret[i-1];
}
int main(){
int ncase,T=1;
init();
cin >> ncase;
while(ncase--) {
scanf("%d",&N);
printf("Case %d: %d\n",T++,ret[N]);
}
return 0;
}

UVa 12716 GCD XOR (简单证明)的更多相关文章

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

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

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

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

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

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

  4. UVA 12716 GCD XOR

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

  5. 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的约数,则可以使用素数筛 ...

  6. UVA 12716 GCD XOR(数论+枚举+打表)

     题意:给你一个N,让你求有多少组A,B,  满足1<= B <= A <= N, 且 gcd(A,B) = A XOR B. 思路:首先我们能够得出两个结论: A-B > ...

  7. UVA - 12716 GCD XOR(GCD等于XOR)(数论)

    题意:输入整数n(1<=n<=30000000),有多少对整数(a, b)满足:1<=b<=a<=n,且gcd(a,b)=a XOR b. 分析:因为c是a的约数,所以枚 ...

  8. UVA 12716 GCD XOR【异或】

    参考:http://www.cnblogs.com/naturepengchen/articles/3952145.html #include<stdio.h> #include<s ...

  9. 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 ...

随机推荐

  1. Android通过泛型简化findViewById类型转换

    曾经老用findViewById,每次使用还得add cast一下今天看到一个视频(依据视频中使用的IDE判断,应该是几年前的视频了..),使用了一个方法,能够不用每次使用findViewById都去 ...

  2. [Android 性能优化系列]内存之基础篇--Android怎样管理内存

    大家假设喜欢我的博客,请关注一下我的微博,请点击这里(http://weibo.com/kifile),谢谢 转载请标明出处(http://blog.csdn.net/kifile),再次感谢 原文地 ...

  3. 0x20 搜索

    这里基本就是入门吧. 可达性统计 用bitset搞的判重,发现这东西是真好用哈,空间还小 #include<cstdio> #include<iostream> #includ ...

  4. 2017第34周复习Java总结

    从上周日开始对工作中遇到的Java相关的知识进行总结整理.先是回顾了Java关键字,重点说了static关键字的用法:修饰变量.程序块.内部类.方法.还静态导包:重点说了final关键字可以修饰类.方 ...

  5. c++面向对象程序设计 谭浩强 第五章答案

    1: #include <iostream> using namespace std; class Student {public: void get_value() {cin>&g ...

  6. Docker容器查看ip地址

    第一步:进入centos7容器:yum install net-tools -y     我这里已经加载过,所以没有继续加载 第二步:加载完成之后可以输入 ifconfig查看ip地址

  7. 粘性固定属性 -- position:sticky

    概述 position: sticky,这是一个比较容易忽略的css3 position 新属性,它的作用即为实现粘性布局,它是 relative 与 fixed 的结合. 用法 默认情况下,其表现为 ...

  8. Repeater 中 OnItemCommand 用法

    <table> <asp:Repeater ID="rptList" runat="server"OnItemCommand="rp ...

  9. Centos下MongoDB数据库的安装以及配置开机自启动(三)

    最近写了一个用node来操作MongoDB完成增.删.改.查.排序.分页功能的示例,并且已经放在了服务器上地址:http://39.105.32.180:3333. 在服务器上完全可以用yum来安装管 ...

  10. 学习篇之SVG

    学习篇之SVG 一.use重用 与 g组合 xmlns变量实际上指示浏览器如何解释称为SVG的XML方言 <g></g> 组合 <use /> 重用 <ell ...