题意:给定一个 n ,让你求有多少对整数 (a, b) 1 <= b <= a 且 gcd(a, b) = a ^ b。

析:设 c = a ^ b 那么 c 就是 a 的约数,那么根据异或的性质 b = a ^ c,那么我们就可以枚举 a 和 c和素数筛选一样,加上gcd, n*logn*logn。

多写几个你会发现 c = a - b,证明如下:

首先 a - b <= a ^ b,且 a - b >= c,下面等于等号,用反证法,假设存在 a - b > c,那么 c < a- b <= a ^ b,然后c = a ^ b矛盾。

然后剩下就好办了。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 30000000;
const LL mod = 10000000000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn+1]; int main(){
memset(a, 0, sizeof(a));
int m = maxn / 2;
for(int i = 1; i <= m; i++)
for(int j = i * 2; j <= maxn; j += i){
int b = j - i;
if(i == (b ^ j)) a[j]++;
}
for(int i = 2; i <= maxn; i++) a[i] += a[i-1]; int cases = 0, T, n; cin >> T;
while(T--){
scanf("%d", &n);
printf("Case %d: %d\n", ++cases, a[n]);
}
return 0;
}

最新文章

  1. Python开发程序:学员管理系统(mysql)
  2. oracle 函数大全及运算符
  3. nload 实时网速查看
  4. 报错:java.io.FileNotFoundException: (系统找不到指定的路径。)
  5. hdu 4542 小明系列故事——未知剩余系
  6. careercup-树与图 4.7
  7. ubuntu安装iscsi
  8. 跟我extjs5(03--在项目过程中加载文件)
  9. JavaScript语言基础知识1
  10. js 增删改查
  11. window配置临时环境变量
  12. 高通 8x12 添加 TP和按键
  13. 金融量化分析【day111】:Matplotib简介
  14. 关于vue监听dom与传值问题
  15. Struts2,springMVC获取request和response
  16. 【数据库】SQL语句解析
  17. oracle数据库无法导出空表的问题解决(开始于oracle11g)
  18. Leetcode刷题记录:构建最大数二叉树
  19. spoj Prime Generator
  20. delphi locate函数的使用

热门文章

  1. java课堂测试—根据模板完成一个简单的技术需求征集系统
  2. how to read openstack code: Core plugin and resource extension
  3. 解决maven Generating project in Interactive mode
  4. 通过k8s(Kubernetes)搭建jmeter的压测环境master-slave架构,实现弹性伸缩
  5. 分布式RPC框架性能大比拼
  6. 类的相互依赖导致StackOverflowError
  7. win8系统 如何不显示这台电脑的文件夹
  8. 【求建议】毕业之声——信院IT类毕业学子经验分享交流会
  9. ubuntu下spring环境搭建
  10. 2 Angular 2 的核心概念