HDU 2136 Largest prime factor 參考代码】的更多相关文章

#include <iostream> #include <vector> #include <cmath> using namespace std; const int MAX=1000001; bool isPrime[MAX];//isPrime[i]=true表示是素数,false表示不是 int indexes[MAX]; //存放素数因子的序号 void eraosthenes() { fill(isPrime,isPrime+MAX,true);//如果0…
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. Inpu…
题意:给你一个数,让你求它的最大因子在素数表的位置. 析:看起来挺简单的题,可是我却WA了一晚上,后来终于明白了,这个第一层循环不是到平方根, 这个题和判断素数不一样,只要明白了这一点,就很简单了. 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring>…
题目梗概:求1000000以内任意数的最大质因数是第几个素数,其中 定义 1为第0个,2为第1个,以此类推. #include<string.h> #include<stdio.h> #include<math.h> ],b[],c[];//b[i]表示i是第几个素数,c[k]表示k的最大素数是c[k],a[i]表示是不是素数 int main() { int n,i,num,j; memset(a,,sizeof(a)); a[]=; b[]=; num=; ;i&l…
题目大意:求出比给出数小的互质的质数个数. 题解:直接用筛法求素数,稍微改编一下,将原先的布尔数组变为数组用来记录信息就可以了. 注意点:大的数组定义要放在程序的开头,不要放在main里面,不然会栈溢出. #include <cstdio> #define max 1000000 }; int main() { int n; ; ; i<max; ++i) { if(prim[i]) continue; for(int j=i; j<max; j+=i) prim[j]=cnt;…
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.   Input…
Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13481    Accepted Submission(s): 4765 Problem Description Everybody knows any number can be combined by the prime number.Now,…
Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6990    Accepted Submission(s): 2471 Problem Description Everybody knows any number can be combined by the prime number. Now…
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.  InputEach line will con…
problem 3:Largest prime factor 题意:求600851475143的最大的质因数 代码如下: #ifndef PRO3_H_INCLUDED #define PRO3_H_INCLUDED #include "prime.h" namespace pro3{ long long solve(){ ;; ;i*i<=n;++i) ){ if(isPrime(n/i))return n/i; else if(isPrime(i))maxn=i; } >…