fork download
  1. import java.io.*;
  2. import java.util.*;
  3. import java.awt.Point;
  4.  
  5. public class ListOfNaturalNumbers {
  6.  
  7. static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
  8. static StringTokenizer st = new StringTokenizer("");
  9.  
  10. public static String next() {
  11. try {
  12. while (!st.hasMoreTokens()) {
  13. String s = br.readLine();
  14. if (s == null)
  15. return null;
  16. st = new StringTokenizer(s);
  17. }
  18. return st.nextToken();
  19. } catch(Exception e) {
  20. return null;
  21. }
  22. }
  23. public static void main(String[] asda) throws Exception {
  24. while (true) {
  25. long N = Long.parseLong( next() );
  26. if (N == 0) {
  27. break;
  28. }
  29. out.println( N == 1 ? 2 : phi(N) );
  30. }
  31. //
  32. out.flush();
  33. System.exit(0);
  34. }
  35. static long [] uniqueFactors(long N) {
  36. ArrayList<Long> list = new ArrayList<Long>();
  37.  
  38. if (N%2 == 0) {
  39. list.add(2L);
  40. while (N%2 == 0) N >>= 1;
  41. }
  42.  
  43. long p = 3;
  44. while (p*p <= N) {
  45. if (N % p == 0) {
  46. list.add(p);
  47. while ( N%p == 0 ) N /= p;
  48. }
  49. p += 2;
  50. }
  51. if (N != 1) {
  52. list.add(N);
  53. }
  54.  
  55. long [] ans = new long [list.size()];
  56. for (int k = 0; k < list.size(); k++) ans[k] = list.get(k);
  57. return ans;
  58. }
  59. static long phi(long N) {
  60. long[] f = uniqueFactors(N);
  61. for (int i = 0; i < f.length; i++) {
  62. N /= f[i];
  63. N *= f[i] - 1;
  64. }
  65. return N;
  66. }
  67.  
  68. }
  69.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class ListOfNaturalNumbers is public, should be declared in a file named ListOfNaturalNumbers.java
public class ListOfNaturalNumbers {
       ^
1 error
stdout
Standard output is empty