素数判断: 一.根据素数定义,该数除了1和它本身以外不再有其他的因数. 详见代码. int prime() { ; i*i<=n; i++) { ) //不是素数 ; //返回1 } ; //是素数返回0 } 二.打表,将所有的素数一一列出,存在一个数组里. 详见代码. void prime() { ; i<; i++) //从2开始一个一个找 { ) //这一个判断可以减少很多重复的,节省很多时间 { ; i*j<; j++) //只要乘以i就一定不是素数 { hash[i*j]=;…
看懂: Max Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3089    Accepted Submission(s): 985 Problem Description To improve the organization of his farm, Farmer John labels each of his N…
Problem Description To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the cows interpret some serial numbers as be…
题目 //下面这个是最先用的方法,因为学姐先讲完这个,所以懒得写代码,就将就着这个用,结果搞了老半天,还是错了,心累.. #include<stdio.h> #include<string.h> int prime[5010]; bool isprime[5010]; int solve(int n) { memset(prime,0,sizeof(prime)); int p=0; for(int i=0; i<=n; i++) isprime[i]=true; ispri…
Max Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10245    Accepted Submission(s): 3304 Problem Description To improve the organization of his farm, Farmer John labels each of his N (1…
完数/最大公约数/最小公倍数/素数/回文数 2015-04-08 10:33 296人阅读 评论(0) 收藏 举报  分类: C/C++(60)  哈尔滨工业大学(8)  版权声明:本文为博主原创文章,未经博主允许不得转载. 1.一个正整数的因子是所有可以整除它的正整数.而一个数如果恰好等于除它本身外的因子之和,这个数就称为完数.例如6=1+2+3(6的因子是1,2,3). #include <stdio.h> #include <math.h> int IsPerfect(int…
这题就是先写个素数筛,存到prime里,之后遍历就好,取余,看是否等于0,如果等于0就更新,感觉自己说的不明白,引用下别人的话吧: 素数打表,找出20000之前的所有素数,存入prime数组,对于每个输入的数a,从prime数组最后一个数往前判断,如果a % prime[当前序号]== 0,那么将该素数就是输入数据a的最大素因子,找出所有输入数据的最大素因子,找出最大的那个对应的数据a即可,当a == 1的时候要特别处理. 然而我现在还是不懂,为什么输入是1 1的时候输出1,题目也没说啊,还有最…
#include<iostream> #include<stdio.h> #include<string.h> #include<cmath> using namespace std; const int maxn=20017; int s[maxn]; int main() { int n,m; int i,j; memset(s,0,sizeof(s)); /*s[1]=1;//埃筛素数 for(i=2; i<maxn; i++) { if(s[i…
To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the cows interpret some serial numbers as better than others. In…
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权!   Description To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct s…