1. 程式人生 > >[板子]質因數分解

[板子]質因數分解

include

include

include

include

include

include

define ll long long

define maxn 1005

using namespace std;
int p[maxn],c[maxn],tot;
void devide(int n){
tot=0;
for(int i=2;i<=sqrt(n);++i){
if(n%i==0){
++tot;
p[tot]=i;
c[tot]=0;
while(n%i==0){
n/=i;
++c[tot];
}
}
}
if(n>1){
++tot;
p[tot]=n;
c[tot]=1;
}
return;
}
int main(){
int n;
scanf("%d",&n);
devide(n);
for(int i=1;i<=tot;++i){
printf("%d %d\n",p[i],c[i]);
}
return 0;
}