Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Main {
  5. static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
  6. static PrintWriter out = new PrintWriter(System.out);
  7.  
  8.  
  9. public static void main(String[] args) {
  10. boolean p[] = new boolean[1001000];
  11. int div[] = new int[1001000];
  12. Arrays.fill(p, true);
  13. p[0] = p[1] = false;
  14. div[1] = 1;
  15. for (int i=2;i<1001000;i++){
  16. if (!p[i]) continue;
  17. div[i] = i;
  18. for (int j=i+i;j<1001000;j+=i){
  19. if (p[j]){
  20. p[j] = false;
  21. div[j] = i;
  22. }
  23. }
  24. }
  25.  
  26. ArrayList<Integer> ans = new ArrayList<>();
  27. for (int i=1;i<=1000000;i++){
  28. int x = i;
  29.  
  30. HashMap<Integer, Integer> counts = new HashMap<>();
  31. while (x>1){
  32. counts.put(div[x], counts.getOrDefault(div[x], 0) + 1);
  33. x /= div[x];
  34. }
  35. int dn = 1;
  36.  
  37. for(Map.Entry<Integer, Integer> cursor : counts.entrySet()){
  38. dn *= cursor.getValue() + 1;
  39. }
  40.  
  41. int a = div[dn], b = dn/div[dn];
  42. if (p[a] && p[b] && a != b) ans.add(i);
  43. }
  44.  
  45. for (int i=8;i<ans.size();i+=9){
  46. out.println(ans.get(i));
  47. }
  48.  
  49. out.close();
  50. }
  51.  
  52. }
  53.  
  54.  
  55. class Pair<F, S> {
  56. public final F first;
  57. public final S second;
  58.  
  59. public Pair(F first, S second) {
  60. this.first = first;
  61. this.second = second;
  62. }
  63.  
  64. @Override
  65. public boolean equals(Object o) {
  66. if (!(o instanceof Pair)) {
  67. return false;
  68. }
  69. Pair<?, ?> p = (Pair<?, ?>) o;
  70. return Objects.equals(p.first, first) && Objects.equals(p.second, second);
  71. }
  72.  
  73. @Override
  74. public int hashCode() {
  75. return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
  76. }
  77.  
  78. public static <A, B> Pair <A, B> create(A a, B b) {
  79. return new Pair<A, B>(a, b);
  80. }
  81. }
  82.  
  83. class FastReader {
  84.  
  85. BufferedReader bf;
  86. StringTokenizer tk = null;
  87. String DELIM = " ";
  88.  
  89. public FastReader(BufferedReader bf) {
  90. this.bf = bf;
  91. }
  92.  
  93. public void skipLine(){
  94. try {
  95. bf.readLine();
  96. } catch (Exception e) {
  97. throw new RuntimeException();
  98. }
  99. }
  100.  
  101. public String nextToken() {
  102. if(tk==null || !tk.hasMoreTokens()) {
  103. try {
  104. tk = new StringTokenizer(bf.readLine(), DELIM);
  105. } catch (Exception e){
  106. throw new RuntimeException();
  107. }
  108. }
  109. return tk.nextToken();
  110. }
  111.  
  112. public int nextInt() {
  113. try {
  114. return Integer.parseInt(nextToken());
  115. } catch (Exception e) {
  116. throw new RuntimeException();
  117. }
  118. }
  119.  
  120. public long nextLong() {
  121. try {
  122. return Long.parseLong(nextToken());
  123. } catch (Exception e) {
  124. throw new RuntimeException();
  125. }
  126. }
  127.  
  128. public double nextDouble() {
  129. try {
  130. return Double.parseDouble(nextToken());
  131. } catch (Exception e) {
  132. throw new RuntimeException();
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement