fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. long n, gcd, primeNumInPow, power;
  10. Scanner in = new Scanner(System.in);
  11. while(in.hasNextLong()){
  12. n = in.nextLong();
  13. gcd = 1;
  14. for(long i = 2; i * i <= n; i++) {
  15. if(n % i == 0) {
  16. power = 0; primeNumInPow = 1;
  17. while(n % i == 0) {
  18. power++;
  19. primeNumInPow *= i;
  20. n /= i;
  21. }
  22. gcd *= (power + 1)*primeNumInPow - power*primeNumInPow/i;
  23. }
  24. }
  25. if (n > 1) gcd *= (2*n - 1);
  26. System.out.println(gcd);
  27. }
  28. }
  29. }
Success #stdin #stdout 0.11s 2249728KB
stdin
1 50 100
stdout
1
195
520