Prime Cuts
2013-04-06 23:49
183 查看
J - Prime CutsCrawling in process...Crawling failedTime Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64uSubmitStatusDescriptionA prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between (andincluding) 1 and N. Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the centerof the list if there are an odd number of prime numbers in the list.InputEach input set will be on a line by itself and will consist of 2 numbers. The first number (1 <= N <= 1000) is the maximum number in the complete list of prime numbers between 1 and N. The second number (1 <= C <= N) defines theC*2 prime numbers to be printed from the center of the list if the length of the list is even; or the (C*2)-1 numbers to be printed from the center of the list if the length of the list is odd.OutputFor each input set, you should print the number N beginning in column 1 followed by a space, then by the number C, then by a colon (:), and then by the center numbers from the list of prime numbers as defined above. If the sizeof the center list exceeds the limits of the list of prime numbers between 1 and N, the list of prime numbers between 1 and N (inclusive) should be printed. Each number from the center of the list should be preceded by exactly one blank. Each line of outputshould be followed by a blank line. Hence, your output should follow the exact format shown in the sample output.Sample Input
21 2 18 2 18 18 100 7Sample Output
21 2: 5 7 11 18 2: 3 5 7 11 18 18: 1 2 3 5 7 11 13 17 100 7: 13 17 19 23 29 31 37 41 43 47 53 59 61 67
//题意:输入两个数字N和C,求在1到N之间的素数中,如果其中素数总是是奇数,则输出中间的2*C-1,如果其中素数总数是偶数,则输出中间的是2*C个素数
//这道题是让我最郁闷的。。。回车符不在一块输的话就会出现runtime error,究竟什么原因呢?
#include<cstdio> #include<cstring> using namespace std; int f[1010],prime[1010]; int count = 0; void Prime() { prime[count++]=1; for(int i=2;i<=1010;i++) if(!f[i]) { prime[count++]=i; for(int j = i*i;j<=1010;j+=i) f[j]=1; } } int main() { Prime(); int n,m,temp; while(scanf("%d%d",&n,&m)!=EOF) { temp=0; while(prime[temp] <= n) temp++; temp--; printf("%d %d:",n,m); if(temp/2>=m) { if(temp%2==1) { for(int i=temp/2-m+1;i<=temp/2+m;i++) printf(" %d",prime[i]); } else { for(int i=temp/2-m+1;i<=temp/2+m-1;i++) printf(" %d",prime[i]); } } else { for(int i=0;prime[i]<=n;i++) printf(" %d",prime[i]); } printf("\n\n"); } return 0; }
相关文章推荐
- poj 1595 Prime Cuts
- hdu1913-Prime Cuts
- joj1148: Prime Cuts
- poj 1595 Prime Cuts
- HDU1319 Prime Cuts
- [暑假集训--数论]poj1595 Prime Cuts
- UVa 406 - Prime Cuts
- zoj 1312 Prime Cuts
- POJ 1595 Prime Cuts
- poj1595-Prime Cuts
- zoj1312 Prime Cuts
- 【筛法打表】poj1595 Prime Cuts
- hdu1319 Prime Cuts
- pku 1319Prime Cuts
- HDU1319---Prime Cuts HDU(111)
- POJ1595 Prime Cuts
- POJ 1595 Prime Cuts
- HDOJ 1319 Prime Cuts<数论>
- UVa OJ 406-Prime Cuts
- POJ-1595-Prime Cuts