给出一篇有关素数线性筛和区间筛的博客,有兴趣的读者可以自取. 本题大意: 给定两个四位的素数,没有前导零,每次变换其中的一位,最终使得两个素数相等,输出最小变换次数.要求变换过程中的数也都是素数. 本题思路: 求最小步数,用BFS,判断素数,用欧拉筛打表. 参考代码: #include <cstdio> #include <queue> #include <map> #include <cstring> using namespace std; ; + ;…
Farey Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14291   Accepted: 5647 Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b)…
P3383 [模板]线性筛素数 题目描述 如题,给定一个范围N,你需要处理M个某数字是否为质数的询问(每个数字均在范围1-N内) 输入输出格式 输入格式: 第一行包含两个正整数N.M,分别表示查询的范围和查询的个数. 接下来M行每行包含一个不小于1且不大于N的整数,即询问该数是否为质数. 输出格式: 输出包含M行,每行为Yes或No,即依次为每一个询问的结果. 输入输出样例 输入样例#1: 复制 100 5 2 3 4 91 97 输出样例#1: 复制 Yes Yes No No Yes 说明…
题意:给一个数 可以写出多少种  连续素数的合 思路:直接线性筛 筛素数 暴力找就行   (素数到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…
题意 哥德巴赫猜想:任一大于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++)…
Longge's problem   Description Longge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 < N < 2^31),you are to calculate ∑gcd(i,…
题意 给出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…
bzoj-3308 九月的咖啡店 题目大意:深绘里在九份开了一家咖啡让,如何调配咖啡民了她每天的头等大事我们假设她有N种原料,第i种原料编号为i,调配一杯咖啡则需要在这里若干种兑在一起.不过有些原料不能同时在一杯中,如果两个编号为i,j的原料,当且仅当i与j互质时,才能兑在同一杯中.现在想知道,如果用这N种原料来调同一杯咖啡,使用的原料编号之和最大可为多少. 数据范围:$1\le N \le 2\cdot 10^5$. 想法: 神仙题..... 主要神仙在,两个根本没法证(至少我现在不会2019…
Maxim and Calculator 题目链接:https://www.luogu.org/problem/CF261E 数据范围:略. 题解: 考试的时候只会暴力,学弟太强了$\%\%\% Orz$. 感觉直接处理不太好处理,得想到所有有可能被这种操作在$100$步表示出来. 先打个表. 之后就随便$dpdp$就好了,关键是你得想到所有合法的数非常小. 我反正是没想到..... 代码: #include <bits/stdc++.h> #define N 3000010 using na…
Description The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices. — It is a matter of security to change such things every now…