public static void main(String[] args){ Scanner sc = new Scanner(System.in); long s = sc.nextLong(); int temp = 2; StringJoiner str= new StringJoiner(" "); while(temp<=s){ if(s%temp==0){ if(temp==s){ str.add(temp+""); break; }else{ str.add(temp+""); s=s/temp; } } else { temp++; } } }这个 是啥问题
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ long num = scanner.nextLong(); if(num <= 3){ System.out.println(num); continue; } for (int i = 2; i <= num; i++) { while (num % i == 0) { System.out.println(i + " "); num /= i; } } } }
#include <stdio.h> #define ARR_LEN 200 #define TABLE_LEN 10000 static char ans[ARR_LEN]; static long numTable[TABLE_LEN] = {2,}; static int numTableLen = 1; char* getResult(long ulDataInput) { int lenAns = 0; memset(ans,0,sizeof(char) * ARR_LEN); while(1 != ulDataInput) { while(0 == ulDataInput%numTable[numTableLen - 1]) { int end = lenAns; long num = numTable[numTableLen - 1]; ans[end] = ' '; end++; while(num) { ans[end] = num%10 + '0'; num = num/10; end++; } for(int i = 0; i < (end - lenAns)/2; i++) { char tmp = ans[lenAns + i]; ans[lenAns + i] = ans[end - 1 - i]; ans[end - 1 - i] = tmp; } lenAns = end; ulDataInput /= numTable[numTableLen - 1]; } if(ulDataInput > numTable[numTableLen - 1]) { for(long i = numTable[numTableLen - 1] + 1; i <= ulDataInput; i++) { int flag = 1; for(int j = 0; j < numTableLen; j++) { if(0 == i%numTable[j]) { flag = 0; break; } } if(flag) { numTable[numTableLen] = i; numTableLen++; break; } } } } ans[lenAns] = '\0'; return ans; } int main() { long n = 0; scanf("%d",&n); printf("%s\n",getResult(n)); return 0; }
#include <stdio.h> #include <string.h> #define N 100 int main() { long i; int j; long n; char over; long devisor[N]; scanf("%ld", &n); j = 0; while(1){ over = 1; for(i=2 ; i<=(n+1)/2 ; i++){ if(n%i == 0){ devisor[j++] = i; n /= i; over = 0; break; } } if(over) break; } for(i=0 ; i<j ; i++){ printf("%ld ", devisor[i]); } printf("%ld \n", n); }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException{ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); Integer num = Integer.valueOf(bufferedReader.readLine()); //System.out.println("num = " + num); for (int i = 2; i <= num; i++){ if (num % i == 0){ System.out.print(i + " "); num = num / i; //重新赋值 i = 1; //重新遍历 } } bufferedReader.close(); } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { long num = sc.nextLong(); System.out.println(getResult(num)); } } private static String getResult (long n) { int a = 2; StringBuffer sb = new StringBuffer(); while (a * a <= n) { while (n % a == 0) { sb.append(a); sb.append(" "); n = n/a; } a++; } // 如果是质数,那就是其本身 if (n > 1) { sb.append(n); sb.append(" "); } return sb.toString(); } }