求素因子 |
Time Limit: 1 Seconds Memory Limit: 32768 K Total Submit:589 Accepted:327 |
Description 任一整数x,找出它的素因子并以如下格式输出: Input 任意整数x (-2100000000<x<2100000000) Output 按照上述格式输出它的素因子(并换行回车) Sample Input -120
Sample Output -120=-2*2*2*3*5 |
Source: #include<iostream.h> #include<cmath> int main() { int x,w; w=0; cin>>x; if(x<0) { w=1; x=-x; } long i,k=sqrt(x); i=2; if(w==1) cout<<"-"<<x<<"=-"; else cout<<x<<"="; while(i<=k) { if(x%i==0) { cout<<i<<"*"; x/=i; k=sqrt(x); continue; } i++; } cout<<x<<endl; return 0; }
|