找到最大的质因子。可以由最小因子除得到
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 int n=in.nextInt(); long res=n; while(true){ int a=findSmallestPrimeFactor(n); n/=a; if(n==1){ res+=1; break; }else{ res+=n; } } System.out.println(res); } public static int findSmallestPrimeFactor(int a){ if(a%2==0){ return 2; } for(int i=3;i*i<=a;i++){ if(a%i==0){ return i; } } return a; } }