2136 Largest prime factor(打表)】的更多相关文章

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…
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…
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,…
题意:给你一个数,让你求它的最大因子在素数表的位置. 析:看起来挺简单的题,可是我却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…
#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…
题目大意:求出比给出数小的互质的质数个数. 题解:直接用筛法求素数,稍微改编一下,将原先的布尔数组变为数组用来记录信息就可以了. 注意点:大的数组定义要放在程序的开头,不要放在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;…
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…
/*打表把素数能组合的数先设置成相应的位数*/ /* if n equals two and n is No.1 position of prime factors  so four position of prime factors is no.1,as well*/ /* although two can combined six but three also can combined six */ /* and three position of prime factors is two…
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…
1. 问题: The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ? 2. 解法(by java in Eclipse) package com.lun.alrithmetic; /* * Q1: what's the primary factor? (1 2 3) * Q2: i & i+2ne能否遍历出所有质数 */ public…
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? #include<stdio.h> #include<string.h> #include<math.h> #include<ctype.h> #include<stdlib.h> #include<stdbool.h>…
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; } >…
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? 欧拉题里很多是关于求质数,求质数的方法很多,我推荐的是筛选法,效率高,也很好理解.百度一下就有详细说明. def primeslist(max): a = [True]*(max+1) # 创建一个list,下标的位置就代表数字 a[0],a[1]=False,False # 0…
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? 翻译过后如下: 找出一个合数的最大质数因子 13195的质数因子有5,7,13和29. 600851475143的最大质数因子是多少? 做出答案以后的题解: 对于给定的n, 使factor = 2, 3, 4, 5, 6..., 对于每个factor, 当factor能被n完全整…
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…
先写一遍思路,跟素数表很类似吧. 1)从小到大遍历数据范围内的所有数.把包含质因子的数的位置都设成跟质因子的位置相同. 2)同一个数的位置可能被多次复写.但是由于是从小到大遍历,这就保证了最后一次写入的是该数的最大质因子的位置 一道题墨迹了好久,上代码分析 #include <iostream> #include <stdio.h> #include <math.h> #include <algorithm> #include <string.h>…
类似于素数打表. #include <cstdio> #include <cstring> #include <algorithm> #define maxn 1000100 using namespace std; int f[maxn]; void inti() { ; ; i<maxn; i++) { ) { num++; for(int j=i; j<maxn; j+=i) { f[j]=num; } } } } int main() { int n…
传送门 题意 给出若干个数n(n<=1000000),求每个n的最大质因子的排名. 质数的排名:如果素数p是第k小的素数,那么p的排名就是k. 思路 乍一看不知道怎么搞. 其实可以想想我们怎么筛素数的,每个数都会被它的质因数筛去. 这就和题目一样了. 代码 #include <cstdio> ; ; int main() { int i, j, x; ; i < MAXN; i++) if(!notpri[i]) { for(j = i; j < MAXN; j += i)…
题目描述: 源码: 需要注意,若使用cin,cout输入输出,会超时. #include"iostream" #include"memory.h" #define MAX 1000000 using namespace std; int index[MAX]; int main() { memset(index, -1, sizeof(index)); index[1] = 0; int sum = 0; for(int i = 2; i < MAX; i++…
题目: Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1 * p2^k2 *...*pm^km. 输入描述: Each input file contains one test case which gives a positive integer N in the range of long int. 输出…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2136 题目大意: 每个素数在素数表中都有一个序号,设1的序号为0,则2的序号为1,3的序号为2,5的序号为3,以此类推.现在要求输出所给定的数n的最大质因子的序号,0<n<1000000. 解题思路: 一开始用暴力超时,想到利用素数筛法,在筛素数的同时,每筛出一个素数就对之后的位置进行染色,比如2就对2的所有倍数染色,染成2的序号,3也是这样,而且会覆盖之前一部分2所染的地方,这样正好符合题意,…
題目:給你一個整數n(不超過14位).求出他的最大的素數因子.假设仅仅有一個素數因子輸出-1. 分析:數論. 直接打表計算10^7內的全部素數因子,然後用短除法除n.記錄最大的因子就可以. 假设最後下的數字不是1,則它就是最大的素數因子. 說明:注意n可能為負數. #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio…
#include <iostream> #include <queue> using namespace std; typedef struct { long v; long next; long cost; }Edge; typedef struct { long v; long cost; }node; bool operator <(const node &a,const node &b) { return a.cost>b.cost; } pri…
HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsum  贪心 HDU 1004 Let the Balloon Rise  字典树,map HDU 1005 Number Sequence  求数列循环节 HDU 1007 Quoit Design  最近点对 HDU 1008 Elevator  模拟 HDU 1010 Tempter of th…
Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8976    Accepted Submission(s): 3191 Problem Description Everybody knows any number can be combined by the prime number. Now…
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…
素数判断: 一.根据素数定义,该数除了1和它本身以外不再有其他的因数. 详见代码. int prime() { ; i*i<=n; i++) { ) //不是素数 ; //返回1 } ; //是素数返回0 } 二.打表,将所有的素数一一列出,存在一个数组里. 详见代码. void prime() { ; i<; i++) //从2开始一个一个找 { ) //这一个判断可以减少很多重复的,节省很多时间 { ; i*j<; j++) //只要乘以i就一定不是素数 { hash[i*j]=;…
本文版权归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…
看懂: 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…