【CSU 1756】Prime】的更多相关文章

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1756 直接暴力O(n^2logn)过不了 两两算gcd 考虑每个数的范围[1,1000]统计一下即可O(1000^2*log(1000)) Notice:1与任何数互质,需要特判(自己与自己互质) Code1 统计 // <1756.cpp> - Wed Oct 19 08:25:53 2016 // This file is made by YJinpeng,created by XuYik…
1619: [例 1]Prime Distance 题目描述 原题来自:Waterloo local,题面详见 POJ 2689 给定两个整数 L,R,求闭区间 [L,R] 中相邻两个质数差值最小的数对与差值最大的数对.当存在多个时,输出靠前的素数对. 输入格式 多组数据.每行两个数 L,R. 输出格式 详见输出样例. 样例 样例输入 2 17 14 17 样例输出 2,3 are closest, 7,11 are most distant. There are no adjacent pri…
[题目链接] http://poj.org/problem?id=2689 [算法] 我们知道,一个在区间[l,r]中的合数的最小质因子必然不超过sqrt(r) 那么,先暴力筛出1-50000中的质数,对于每个询问,用筛出的质数标记[l,r]中的合数,即可 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale&g…
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1079 现有一棵有N个顶点的树,顶点的标号分别为1, 2, …, N.对于每个形如a b k的询问,你需要回答在从点a到点b的路径上是否包含点k. DFS序&欧拉序列  LCA-最近公共祖先 看完这两篇文章就会做了 首先找出a,b的最近公共祖先p(Because 树上路径→(a→p→b)),我们要找这条路上是否存在点k 转换:k要在p的子树中 && (a||b)任意一点在p的子树中.…
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1803 Solution: 考虑两个数x,y乘积%2016=0 x×y≡0(MOD 2016) x=p1×2016+q1 y=p2×2016+q2 x×y=(p1×2016+q1)×(p2×2016+q2)=2016^2×p1p2+2016(p1q2+q1p2)+p1p2≡0(MOD 2016) 实际上就转化为余数乘积取模=0,预处理没两个余数乘积是否mod2016=0 统计答案两个余数出现的个数…
Prime Numbers  Descriptions: A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a program which reads a list of N integers and p…
Prime Path 原文是English 这里直接上中文了 Descriptions: 给你两个四位的素数a,b.a可以改变某一位上的数字变成c,但只有当c也是四位的素数时才能进行这种改变.请你计算a最少经过多少次上述变换才能变成b.例如:1033 -> 8179 1033 1733 3733 3739 3779 8779 8179最少变换了6次.Input 第一行输入整数T,表示样例数. (T <= 100) 每个样例输入两个四位的素数a,b.(没有前导零) Output 对于每个样例,输…
题 Description Jerry is caught by Tom. He was penned up in one room with a door, which only can be opened by its code. The code is the answer of the sum of the sequence of number written on the door. The type of the sequence of number is 1^m + 2^m + 3…
Codeforces 912 E 题意:给\(n\leq16\)个素数\(p_1..p_n\),求第\(k\)个所有质因数都在\(n\)个数中的数. 思路:折半搜索...我原来胡搞毛搞怎么也搞不动\(16\)的点...直到我突然想到了分成两个\(8\)来搞... 首先我们发现\(n\leq8\)的我们二分+搜索就可以很简单地解决,那么我们据此来搞搞\(n\leq16\)的点. 我们将这些素数分成\(p_1..p_{\lfloor n/2\rfloor}\).\(p_{\lfloor n/2\rf…
Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. Input 输入包含不超过 30 组数据. 每组数据包含两个整数 n,m (1≤n,m≤109). Output 对于每组数据,输出一个整数表示满足条件的数量. Sample Input 32 63 2016 2016 1000000000 1000000000 Sample Output 1 30576 752314689550…