-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11112.cpp
More file actions
40 lines (37 loc) · 955 Bytes
/
11112.cpp
File metadata and controls
40 lines (37 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<iostream>
#include<cmath>
using namespace std;
const int N=1e7+10;
typedef long long ll;
ll cnt;//质数的数量
ll primes[N];//从2到n的质数集
bool st[N];//判断是否为质数
void get_primes(ll n){
for(ll i=2;i<=n;i++){
if(!st[i]) primes[cnt++]=i;
for(ll j=0;primes[j]<=n/i;j++){
//primes[j]<=n/i:primes[j]*i<=n把大于n的合数都筛没啥意义了
st[primes[j]*i]=true;//用最小质因子去筛合数
if(i%primes[j]==0) break;
}
}
}
int main(){
get_primes(10000000);
ll t;scanf("%lld",&t);
while(t--){
ll n;scanf("%lld",&n);
for(int i=0;i<cnt;i++){
if(n%primes[i]==0){
n/=primes[i];
if(n%primes[i]==0){
cout<<primes[i]<<' '<<n/primes[i]<<'\n';
break;
}
else cout<<(ll)sqrt(n)<<' '<<primes[i]<<'\n';
break;
}
}
}
return 0;
}