'commit'
This commit is contained in:
33
TangDou/LuoGuBook/P1075_2.cpp
Normal file
33
TangDou/LuoGuBook/P1075_2.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 44721 + 10; // 2e9=2000000000
|
||||
|
||||
//欧拉筛
|
||||
int primes[N], cnt; // primes[]存储所有素数
|
||||
bool st[N]; // st[x]存储x是否被筛掉
|
||||
void get_primes(int n) {
|
||||
for (int i = 2; i <= n; i++) {
|
||||
if (!st[i]) primes[cnt++] = i;
|
||||
for (int j = 0; primes[j] <= n / i; j++) {
|
||||
st[primes[j] * i] = true;
|
||||
if (i % primes[j] == 0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
// cout << sqrt(2e9) << endl;
|
||||
int n;
|
||||
cin >> n;
|
||||
get_primes(sqrt(n)); //计算n的所有小质数因子范围 1~sqrt(n)
|
||||
|
||||
//枚举每个质数因子,看看它是不是n的约数
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
if (n % primes[i] == 0) {
|
||||
cout << n / primes[i] << endl; //找出对应的大质数因子
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user