HDOJ Problem-2136 Largest prime factor(素數打表法)
Largest prime factor
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17192 Accepted Submission(s): 5977
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
Each line will contain one integer n(0 < n < 1000000).
Output
Output the LPF(n).
Sample Input
1 2 3 4 5
Sample Output
0 1 2 1 3
Author
Wiskey
Source
Recommend
威士忌 | We have carefully selected several similar problems for you: 2138 2133 2135 1215 2137
題目分析:
求一個數的最大質因子的位置。所以要用打表法來做!
程式碼如下:
#include<iostream> #define maxn 1000001 using namespace std; int prime[maxn]; void prepare() { int k=1; for(int i=2;i<maxn;i++) { if(prime[i]==0) { for(int j=1;j*i<maxn;j++) prime[j*i]=k; k++; } } } int main() { prepare(); int T; while(~scanf("%d",&T)) { printf("%d\n",prime[T]); } return 0; }
相關推薦
HDOJ Problem-2136 Largest prime factor(素數打表法)
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 17192 Ac
HDU 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 lar
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 lar
素數打表法
stdio.h clu fine pan prime bsp 題意 col i++ 很多時間超限的問題都與素數有關 #include <stdio.h>#define maxn 1000000//根據題意大概估算範圍;int prime[maxn];void g
Largest prime factor(最大素數因子)
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others
HDU Largest prime factor(埃拉托色尼篩選法求素數模板法改動)
題意:給你一個數,求它這個數的最大素因子在素數表的第幾位 思路:剛開始思路有一點錯誤,看錯誤程式碼 錯誤程式碼: #include <iostream>0 #include <cs
hdu 4135 Co-prime (素數打表+容斥原理)
string tdi eof AR Go data tor tom void 題目鏈接 題意:問從A到B中與N互素的個數。 題解: 利用容斥原理:先求出與n互為素數的個數。 可以先將 n 進行素因子分解,然後用區間 x 除以 素因子,就得到了與 n 的 約數是那個素因子的個
CodeForces - 271B Prime Matrix (素數打表)
You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an
3520: Prime Palindromes (素數打表)
3520: Prime Palindromes 時間限制(普通/Java):1000MS/3000MS 記憶體限制:65536KByte 描述 The number 151 is a prime palindrome because i
projecteuler#3 Largest prime factor
* Prime.php <?php /** https://projecteuler.net/problem=3 The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime fac
271B Prime Matrix (素數打表)
You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an
bfs+素數打表(poj3126 prime path)
The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numb
(hdu step 2.1.3)Largest prime factor(求一個數的最大質因子的位置)
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
3421(X-factor Chains) 素數打表+唯一分解定理+組合數學
題目連結 題目分析: 大意:給定一個數X(X<=2^20),題幹給定數列:1 = X0, X1, X2, …, Xm = X 且要求數列 ①Xi<X(i+1);②Xi | X(i+1) 即Xi 整除 X(i+1)。 求符合要求的最大長度的數列,輸出這種
Prime Distance poj 2689 區間內的素數打表模板
#include<iostream> #include<cstdio> #include<cstring> #include<math.h> using namespace std; #define M 1000005 #define N 1 <
【☆】素數打表--重要
sca %d col logs printf i++ amp pan 題目 題目:找出n以內的素數(n<100) 這裏只找出一組 代碼: 1 #include<stdio.h> 2 int main() 3 { 4 int n,i,j
Goldbach`s Conjecture LightOJ - 1259 (素數打表 哥德巴赫猜想)
rim inf clu 就是 include str cst name long long 題意: 就是哥德巴赫猜想。。。任意一個偶數 都可以分解成兩個(就是一對啦)質數的加和 輸入一個偶數求有幾對。。 解析: 首先! 素數打表。。因為 質數 + 質數 = 偶數 所以 偶數
Codeforces385C Bear and Prime Numbers(數論+打表)
題意:給一個數列(無規則排列,會重複)再給m個查詢範圍,查詢每個查詢範圍內的素數能整除數列中的數的數量和(有點繞口) 其實這道題本質上不是很難,然後T的我想吐。先篩一個素數表,然後一邊打表一邊做一個字首和的統計。我用的類似埃氏篩法做表,因為我之前用歐氏篩法做表,莫名WA了,然後用了比較擅長的
素數打表——找出1~100以內的素數
esp ace ++ str clu += iostream space ostream 素數篩選法: #include <iostream> using namespace std; //素數打表模板 bool is_prime[100]; i