#11186: 有誰能夠測試2856這個數字


abcjava (unknown)


import java.util.Scanner;
public class JAVA {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner cin = new Scanner(System.in);

int a;
while(cin.hasNextInt()){
a = cin.nextInt();
int c =2;
int i = 0;
boolean check = true;
while(a != 1){
if(a % c == 0 ){
a /= c;
if(c > 2 && i == 1)
System.out.print(" * ");
i = 1;
if(check){
System.out.print(c);
check = false;
}else{
System.out.print("^" + c);
}
}else{
c++;
check = true;
}

}
System.out.println();
}
}
}

這是我的code 但是我測試 2856這個數字 應該是 2^2^2 * 3 * 7 *17 正確答案是 2^2 *3^2 * 7 *17 ??

我的測試結果是WA 求解!!!!! 

 

#11192: Re:有誰能夠測試2856這個數字


timmymike (超小小蝦米)


import java.util.Scanner;
public class JAVA {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner cin = new Scanner(System.in);

int a;
while(cin.hasNextInt()){
a = cin.nextInt();
int c =2;
int i = 0;
boolean check = true;
while(a != 1){
if(a % c == 0 ){
a /= c;
if(c > 2 && i == 1)
System.out.print(" * ");
i = 1;
if(check){
System.out.print(c);
check = false;
}else{
System.out.print("^" + c);
}
}else{
c++;
check = true;
}

}
System.out.println();
}
}
}

這是我的code 但是我測試 2856這個數字 應該是 2^2^2 * 3 * 7 *17 正確答案是 2^2 *3^2 * 7 *17 ??

我的測試結果是WA 求解!!!!! 

 


正確答案應該是2^3 * 3 * 7 * 17,題目有說,「^」是次方符號唷!^^

---------------------------------------------------------------------------------------------------------------------

參考資料

自己

資料來源

大腦