Besides the ordinary Boy Friend and Girl Friend, here we define a more academic kind of friend: Prime Friend. We call a nonnegative integer A is the integer B’s Prime Friend when the sum of A and B is a prime. So an integer has many prime friends, fo…
Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2. This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actu…
The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are sm…
用线性筛来筛,复杂度O(n) #include<bits/stdc++.h> #include<ext/rope> #define fi first #define se second #define mp make_pair #define pb push_back #define pii pair<int,int> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mo…
标题效果:定整N(N <= 1e7),乞讨1<=x,y<=N和Gcd(x,y)素数的数(x,y)有多少.. 思考:推,. 建立gcd(x,y) = p,然后,x / p与y / p互素 问题就转化成了N / p中有多少个数互质,然后累加就能够了. =>对于随意a,b,a <= N / p,b <= N / p,且a与b互质 =>gcd(a,b) == 1 如今问题就非常明显了.看到这个形式就非常easy想到欧拉函数.求一下phi,算一下前缀和,累加. 注意这里求欧…
题意 哥德巴赫猜想:任一大于2的数都可以分为两个质数之和 给一个n 分成两个质数之和 线行筛打表即可 可以拿一个数组当桶标记一下a[i]  i这个数是不是素数  在线性筛后面加个装桶循环即可 #include<cstdio> #include<cstring> using namespace std; ]; ]; int cnt; void Prime(int n){ cnt=; memset(Is_Primes,,sizeof(Is_Primes)); ;i<=n;i++)…
题意:给一个数 可以写出多少种  连续素数的合 思路:直接线性筛 筛素数 暴力找就行   (素数到n/2就可以停下了,优化一个常数) 其中:线性筛的证明参考:https://blog.csdn.net/nk_test/article/details/46242401 https://blog.csdn.net/qq_40873884/article/details/79124552 https://blog.csdn.net/baoli1008/article/details/50788512…
题意 给出a d n    给出数列 a,a+d,a+2d,a+3d......a+kd 问第n个数是几 保证答案不溢出 直接线性筛模拟即可 #include<cstdio> #include<cstring> using namespace std; ]; ]; ]; int cnt; void Prime(int n){ cnt=; memset(Is_Primes,,sizeof(Is_Primes)); ;i<=n;i++){ if(!Is_Primes[i]) Pr…
标题效果:有一个格子组件图,假设三个人在一条直线上,那么第一个人将不会看到第三人.现在,有一个人站在(1,1)在.我问他是否能看到n*n的人数的矩阵. 思考:如果你想站(1,1)这名男子看到了一个立场(x,y)一个人.gcd(x,y) == 1,这是一个经典的模型,仅仅要求出n以内phi的和就能够了. 方法就是线性筛. CODE: #include <cstdio> #include <cstring> #include <iostream> #include <…
题意:给出两数乘积K(1e100) 和 一个数L(1e6)  问有没有小于L(不能等于)的素数是K的因数 思路:把数K切割 用1000进制表示   由同余模公式知   k%x=(a*1000%x+b*1000*1000%x+c*1000*1000*1000%x....) a b c等为 相应位置的三位数  这样切割可以减少模的次数 防止超时 #include<cstdio> #include<cstring> #include<vector> #include<c…