思路:将输入的这个数分成n个素数的相乘的结果,用一个数组存储起来.之后再输出就能够了 Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6633    Accepted Submission(s): 3971 Problem Description Eddy's interest is very ext…
// Eddy 继续 Problem Description As is known, Ackermann function plays an important role in the sphere of theoretical computer science. However, in the other hand, the dramatic fast increasing pace of the function caused the value of Ackermann function…
题意:输入一个数判断是不是素数,并规定2不是素数. 析:一看就很简单吧,用素数筛选法,注意的是结束条件是n<0,一开始被坑了... 不说了,直接上代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; typedef long long LL; const int maxn = 16000 + 10; int p…
题目 简单的计算A,B之间有多少个素数 只是测试数据有是负的 //AC //A和B之间有多少个素数 //数据可能有负的!!! #include<string.h> #include<stdio.h> //素数筛选法 +];//1 合数, 0 素数 void Prime() { memset(pri,,sizeof(pri)); pri[]=pri[]=; ;i<;i++) { ) ;j=j+i) pri[j]=; } } int main() { int a,b; Prime…
题意:给出一个区间[L,U],找出区间里相邻的距离最近的两个素数和距离最远的两个素数. 用素数筛选法.所有小于U的数,如果是合数,必定是某个因子(2到sqrt(U)间的素数)的倍数.由于sqrt(U)最大也只有2^16,所以我们可以用素数筛选法,先预处理出2~2^16之间的素数,然后再用这些素数筛选出L~U之间的素数.接着就好办了. 有几个要注意的是:1:L为1的情况,可以通过令L=2或者标记isp[0]=false.2:建议用long long,否则很容易在过程中超int范围,导致数组越界RE…
http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问有几组这样的(a,b) 比较简单的哥德巴赫猜想题,不需要多说,但一般的素数判定会TLE,所以这里用的是素数筛选法 这里需要注意的是筛选出来素数数组的大小 #include<stdio.h> #include<math.h> #include<string.h> #inclu…
http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34323   Accepted: 13169 Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic…
Problem Description Everybody knows any number can be combined by the prime number. Now, your task is telling me what position of the largest prime factor. The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc. Specially, LPF(1) = 0.   In…
废话不多说,先上题目. 51nod Codeforces 两个其实是一个意思,看51nod题目就讲的很清楚了,题意不再赘述. 直接讲我的分析过程:刚开始拿到手有点蒙蔽,看起来很难,然后......然后我就开始一顿胡蒙,各种举例子.找规律下面为我取n = 10的过程. 1.首先1肯定不用取.因为它太特殊了,如果 取它的话,只能判断是不是1,因为所有数都是1的倍数:反之其他所有情况排除了就选它,不用浪费次数来取它. 2.素数肯定是要取的.因为......因为这题一看就是考素数的题. 3.以10为例,…
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为int根号后大小不超过60000. 即因子的大小不会超过60000,除非本身是质数. int 4 -2147438648-+2147438647long int 4 -2147438648-+2141438647 #include <iostream> #include <cstdio>…
用vis标记出现过的id,checked标记询问过的id.至于如何判断排名为素数,用素数筛选法预处理一下即可,水题. #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> using namespace std; /* 素数筛选法 */ +; int isPrime[maxn]; int vis[maxn]; int checked[maxn]; int…
素数筛选法比较有名的,较常用的是Sieve of Eratosthenes,为古希腊数学家埃拉托色尼(Eratosthenes 274B.C.-194B.C.)提出的一种筛选法.详细步骤及图示讲解,还有java与c++版源代码. void runEratosthenesSieve(int upperBound) { int upperBoundSquareRoot = (int)sqrt((double)upperBound); ]; memset(isComposite, , )); ; m…
对于数论的学习比较的碎片化,所以开了一篇随笔来记录一下学习中遇到的一些坑,主要通过题目来讲解 本题围绕:素数筛选法与空间换时间 HDU4548美素数 题目描述 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数.给定一个区间,你能计算出这个区间内有多少个美素数吗? 输入 第一行输入一个正整数T,表示总共…
http://acm.hdu.edu.cn/showproblem.php?pid=1164 题意很简单,只是写代码的时候需要注意几个问题 一.筛选素数的时候记得用埃式筛选法,要是直接找可能会WA. int prime(int n) { int flag = 0; for(int i=2;i<=sqrt(n);i++) { if(n%i==0){ flag = 1;break; } } if(flag==1) return 0; else return 1; } void solve() { f…
何为"打表"呢,说得简单点就是: 有时候与其重复运行同样的算法得出答案,还不如直接用算法把这组数据所有可能的答案都枚举出来存到一个足够大的容器中去-例如数组(打表),然后再输入数据的时候,直接遍历容器,检索这个数据是否有题意要求的结果. 举一个几乎所有程序员都知道的简单例子= =: 求素数(POJ 1595)-Prime cuts 这一题大意是给出 多组N(1~1000)和C,让你从N内素数的中间项向外扩展C个素数,比如给出7 1,素数有5个(注意此题出题人坑爹得让1作为"素…
Prime Distance Time Limit: 2 Seconds      Memory Limit: 65536 KB The branch of mathematics called number theory is about properties of numbers. One of the areas that has captured the interest of number theoreticians for thousands of years is the ques…
Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5793    Accepted Submission(s): 3459 Problem Description Eddy's interest is very extensive, recently he is interested in prime n…
题目链接 题意 : 给你一个数,让你用它的素数质因子表示出来. 思路 : 先打一下表,因为会有重复的质因子,所以从大到小开始找,并且找到一个之后不能就接着往下找,要再找一遍这个数. #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> using namespace std ; ] ; void sett() { int i,j; ; i <= ; ++…
链接:传送门 题意:给出一个整数 n ,输出整数 n 的分解成若干个素因子的方案 思路:经典的整数分解题目,这里采用试除法 和 用筛法改造后的试除法 对正整数 n 进行分解 方法一:试除法对正整数 n 进行分解 /************************************************************************* > File Name: hdu1164.cpp > Author: WArobot > Blog: http://www.cnb…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 [题目大意] 给你n个点的坐标,让你找到联通n个点的一种方法.保证联通的线路最短,典型的最小生成树问题. 方法一 . 通过不断找到最小的边来找到终于结果. Kruskal 算法 #include <iostream> #include <algorithm> #include <cstdio> #include <cmath> using namespac…
Everybody knows any number can be combined by the prime number. Now, your task is telling me what position of the largest prime factor. The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc. Specially, LPF(1) = 0. Input Each line will con…
#include<iostream>using namespace std;const int N=1000002;int array[N]={0};int main(){ int n; for(int i=5;i<=N;i+=4){  for(int j=5;j<=N;j+=4){   int num=i*j;   if(i*j>N)   break;   if(array[i]==0&&array[j]==0)   //如果 i,j 目前都不为两个数的乘积…
快速查找素数 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 现在给你一个正整数N,要你快速的找出在2.....N这些数里面所有的素数.   输入 给出一个正整数数N(N<=2000000)但N为0时结束程序.测试数据不超过100组 输出 将2~N范围内所有的素数输出.两个数之间用空格隔开 样例输入 5 10 11 0 样例输出 2 3 5 2 3 5 7 2 3 5 7 11 /* Name: NYOJ--187--快速查找素数 Copyright: ©201…
. Hungry Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money,…
D. Soldier and Number Game time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the seco…
http://lightoj.com/volume_showproblem.php?problem=1197 题目大意: 就是给你一个区间[a,b]让你求这个区间素数的个数 但a.b的值太大没法直接进行素数筛选(没法开那么大的数组),我们可以将a当做0,将b当做b-a 这样求[a,b]之间就变成了求[0, b - a]之间,这样就可以开数组来筛选 下图是代码式子j = j + prime[i] - a % prime[i]的由来 #include<stdio.h> #include<ma…
转自:http://blog.csdn.net/dream_you_to_life/article/details/43883367 作者:Sky丶Memory 1.一个数是否为质数的判定. 质数,只有1和其本身才是其约数,所以我们判定一个数是否为质数,只需要判定2~(N - 1)中是否存在其约数即可,此种方法的时间复杂度为O(N),随着N的增加,效率依然很慢.这里有个O()的方法:对于一个合数,其必用一个约数(除1外)小于等于其平方根(可用反证法证明),所以我们只需要判断2-之间的数即可. b…
1009: 一带一路 时间限制: 1 Sec  内存限制: 128 MB 题目描述 一带一路是去去年习大大提出来的建设“新丝绸之路经济带”和“21世纪海上丝绸之路”的战略构想.其中就包括我们新疆乌鲁木齐,所以这也是对新疆来说是一个巨大的机遇.我们新疆要加强和周边国家的经济文化交流,就必然要和周边国家城市修许多路.现在假设有N座城市,每一个城市都有一个投资指标数,例如A城市和B城市的投资指标数分别为Ia和Ib,如果Ia或Ib或Ia-Ib的绝对值为素数或者为1,则A城市和B城市可以修路,否则不能.他…
刚刚学了一种新的素数筛选法,效率比原先的要高一些,据说当n趋近于无穷大时这个的时间复杂度趋近O(n).本人水平有限,无法证明. 这是道水题,贴代码出来重点是欧拉筛选法.我把原来普通的筛选法贴出来. //2013-11-07-22.30 //poj 2909 #include <stdio.h> #include <string.h> const int maxn = (1<<15)+5; bool vis[maxn]; int pr[3416]; int cnt = 1…
Problem Description Eddy's interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can't write program, so Eddy has to ask intelligent you to h…