做一個類似與素數篩之類的預處理,然後就OK了。。
#include <iostream>
#include<stdio.h>
#include<vector>
#include<queue>
#include<stack>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define LL long long
#define lcm(a,b) (a*b/gcd(a,b))
//O(n)求素數,1-n的歐拉數
#define N 1000001
int phi[N];
int yu[N];
void init()
{
for(int i=2;i<N;i++)
{
for(int j=i;j<N;j+=i)
{
phi[j]++;
if(yu[j]==0)yu[j]=i;
}
}
}
int main()
{
int p;
init();
while(~scanf("%d",&p))
{
int x=phi[p];
int y=yu[p];
printf("%d %d\n",x,p/y);
}
return 0;
}