GCD = XOR(GCD XOR )
首先没看懂XOR(于是百度了一下):异或,英文为exclusive OR,或缩写成xor。同时还有一个OR,于是一起看了一眼:
大意:
输入一个整数n,在1~n内,有多少对整数(a,b)满足GCD(a,b)== a XOR b。
看着这个脑中闪过暴力,因为 a ^ b = c, 则 a ^ c = b,所以直接枚举a和c就好,然后算出 b = a ^ c,最后 if ( GCD( a, b) == c )就好。
后来看了一下大佬的博客发现还有更简便的做法。
于是乎自己敲了一份:
#include <cstdio>
const int MAX = ;
int ans[MAX]; void pre()
{
for (int i = ; i < MAX; i++) // i 即 a - b
{
for (int j = i + i; j < MAX; j += i) // j 即 a
if ((j ^ (j - i)) == i) // 判断是否有 a ^ b == a - b
ans[j] ++;
ans[i] += ans[i - ];
}
} int main()
{
pre(); //打表即可
int t;
scanf("%d", &t);
for (int i = ; i <= t; i++)
{
int n;
scanf("%d", &n);
printf("Case %d: %d\n", i, ans[n]);
}
return ;
}
GCD = XOR(GCD XOR )的更多相关文章
- 【CJOJ2512】gcd之和(莫比乌斯反演)
[CJOJ2512]gcd之和(莫比乌斯反演) 题面 给定\(n,m(n,m<=10^7)\) 求 \[\sum_{i=1}^n\sum_{j=1}^mgcd(i,j)\] 题解 首先把公因数直 ...
- 【BZOJ2115】Xor(线性基)
[BZOJ2115]Xor(线性基) 题面 BZOJ Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si ...
- 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的约数,则可以使用素数筛 ...
- UVA - 12716 GCD XOR(GCD等于XOR)(数论)
题意:输入整数n(1<=n<=30000000),有多少对整数(a, b)满足:1<=b<=a<=n,且gcd(a,b)=a XOR b. 分析:因为c是a的约数,所以枚 ...
- [USACO]6.1.3 cow xor(二进制+Trie)
题意:给你一个序列(n<=100000),求出一个连续的子序列[i,j]使得ai xor ai+1 xor…… xor aj最大,求出这个最大值(其中每个数<=2^21) 分析:题目和求一 ...
- SPOJ - PGCD Primes in GCD Table(莫比乌斯反演)
http://www.spoj.com/problems/PGCD/en/ 题意: 给出a,b区间,求该区间内满足gcd(x,y)=质数的个数. 思路: 设f(n)为 gcd(x,y)=p的个数,那么 ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 xor (根号分治)
xor There is a tree with nn nodes. For each node, there is an integer value a_iai, (1 \le a_i \le ...
- 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)- XOR(二进制使用)
链接:https://www.nowcoder.com/acm/contest/116/H来源:牛客网 题目描述 Once there was a king called XOR, he had a ...
- HDU 5344 MZL's xor (多校)[补7月28]
MZL's xor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
随机推荐
- Vim经常使用技巧总结2
我的主力博客:半亩方塘 1. 在光标所在行查找字符在普通模式下用 f{char} 命令,光标会移动到该字符所在的位置.向下反复查找在普通模式下用 ;,向上回退查找用 , 2. 在光标所在行查找与替换在 ...
- mysql order by的一些技巧
1. 只按日期排序,忽略年份> select date, description from table_name order by month(date),dayofmonth(date);注意 ...
- LeetCode(28)题解:Implement strStr()
https://leetcode.com/problems/implement-strstr/ 题目: Implement strStr(). Returns the index of the fir ...
- 我遇到的错误curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused
今天我用curl命令,无论如何都是出现: curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused 找了很久,不知道 ...
- 4.改变eclipse选中文字颜色
window-preferences-general-editors-text editors-annotations-occurrences 和 window-preferences-general ...
- 百度自然语言处理api用法
def words url = "https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?access_token=1111111" param ...
- SpringBoot启动跟踪
程序启动入口 @SpringBootApplication public class Chapter001Application { public static void main(String[] ...
- HDU4289 Control —— 最小割、最大流 、拆点
题目链接:https://vjudge.net/problem/HDU-4289 Control Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- 让th里面的东西自动换行
让th里面的东西自动换行 html中的TH里面的文字不管多长,始终是一行,很烦 <th style="word-wrap:break-word;">aaaaaaaaaa ...
- ORACLE 创建表空间及用户
/*创建存放原始数据的表空间*/ create tablespace Djzh_original datafile 'E:\APP\ADMINISTRATOR\ORADATA\ORCL\Djzh_or ...