Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class S4_2018{
  5.  
  6. static HashMap<Long, Long> set = new HashMap<Long, Long>();
  7. public static void main(String[] args) throws IOException {
  8. long N = readLong(); set.put((long) 1, (long) 1); println(rekt(N));
  9. exit();
  10. }
  11.  
  12. public static long rekt(long n) {
  13. if(n == 1) return 1;
  14. if(set.containsKey(n)) return set.get(n);
  15. long ans = 0;
  16. // System.out.println(N);
  17. for(int i = 2; i<=Math.sqrt(n); i++) ans += rekt(n/i);
  18. int last = (int) Math.sqrt(n);
  19. for(int j = (int) Math.sqrt(n); j>=1; j--) {
  20. ans += (Math.floor(n/1.0/j)-last)*rekt(j);
  21. last = (int) Math.floor(n/1.0/j);
  22. }
  23. set.put(n, ans);
  24. return ans;
  25. }
  26.  
  27. static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  28. static StringTokenizer st;
  29. static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  30.  
  31. static String next() throws IOException {
  32. while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine().trim());
  33. return st.nextToken();
  34. }
  35.  
  36. static int readInt() throws IOException {return Integer.parseInt(next());}
  37. static long readLong() throws IOException {return Long.parseLong(next());}
  38. static String readLine() throws IOException {return br.readLine().trim();}
  39. static void print(Object o) {pr.print(o);}
  40. static void println(Object o) {pr.println(o);}
  41. static void println() {pr.println();}
  42.  
  43. static void exit() throws IOException {
  44. br.close();
  45. pr.close();
  46. System.exit(0);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement