2011-06-17 13:03:40Morris
[JAVA] a010. 因數分解
/**********************************************************************************/
/* Problem: a010 "因數分解" */
/* Language: JAVA */
/* Result: AC (104ms, 5604KB) on ZeroJudge */
/* Author: new1028 at 2011-06-17 10:36:27 */
/**********************************************************************************/
import java.util.Scanner;
import java.lang.Math.*;
public class a010 {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int N, a, t, sq, flag;
while(cin.hasNext()) {
N = cin.nextInt();
sq = (int)Math.sqrt(N);
flag = 0;
for(a = 2; a <= sq; a++) {
if(N%a == 0) {
t = 0;
while(N%a == 0) {
t++; N /= a;
}
if(flag != 0)
System.out.print(" ");
flag = 1;
if(t != 1)
System.out.print(a + "^" + t);
else
System.out.print(a);
if(N != 1)
System.out.print(" *");
}
}
if(flag != 0)
System.out.print(" ");
if(N != 1)
System.out.print(N);
System.out.println();
}
}
}
/* Problem: a010 "因數分解" */
/* Language: JAVA */
/* Result: AC (104ms, 5604KB) on ZeroJudge */
/* Author: new1028 at 2011-06-17 10:36:27 */
/**********************************************************************************/
import java.util.Scanner;
import java.lang.Math.*;
public class a010 {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int N, a, t, sq, flag;
while(cin.hasNext()) {
N = cin.nextInt();
sq = (int)Math.sqrt(N);
flag = 0;
for(a = 2; a <= sq; a++) {
if(N%a == 0) {
t = 0;
while(N%a == 0) {
t++; N /= a;
}
if(flag != 0)
System.out.print(" ");
flag = 1;
if(t != 1)
System.out.print(a + "^" + t);
else
System.out.print(a);
if(N != 1)
System.out.print(" *");
}
}
if(flag != 0)
System.out.print(" ");
if(N != 1)
System.out.print(N);
System.out.println();
}
}
}
上一篇:[JAVA] a009. 解碼器
下一篇:d816. 不要再晃啦!