Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Main {
- static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
- static PrintWriter out = new PrintWriter(System.out);
- public static void main(String[] args) {
- boolean p[] = new boolean[1001000];
- int div[] = new int[1001000];
- Arrays.fill(p, true);
- p[0] = p[1] = false;
- div[1] = 1;
- for (int i=2;i<1001000;i++){
- if (!p[i]) continue;
- div[i] = i;
- for (int j=i+i;j<1001000;j+=i){
- if (p[j]){
- p[j] = false;
- div[j] = i;
- }
- }
- }
- ArrayList<Integer> ans = new ArrayList<>();
- for (int i=1;i<=1000000;i++){
- int x = i;
- HashMap<Integer, Integer> counts = new HashMap<>();
- while (x>1){
- counts.put(div[x], counts.getOrDefault(div[x], 0) + 1);
- x /= div[x];
- }
- int dn = 1;
- for(Map.Entry<Integer, Integer> cursor : counts.entrySet()){
- dn *= cursor.getValue() + 1;
- }
- int a = div[dn], b = dn/div[dn];
- if (p[a] && p[b] && a != b) ans.add(i);
- }
- for (int i=8;i<ans.size();i+=9){
- out.println(ans.get(i));
- }
- out.close();
- }
- }
- class Pair<F, S> {
- public final F first;
- public final S second;
- public Pair(F first, S second) {
- this.first = first;
- this.second = second;
- }
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof Pair)) {
- return false;
- }
- Pair<?, ?> p = (Pair<?, ?>) o;
- return Objects.equals(p.first, first) && Objects.equals(p.second, second);
- }
- @Override
- public int hashCode() {
- return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
- }
- public static <A, B> Pair <A, B> create(A a, B b) {
- return new Pair<A, B>(a, b);
- }
- }
- class FastReader {
- BufferedReader bf;
- StringTokenizer tk = null;
- String DELIM = " ";
- public FastReader(BufferedReader bf) {
- this.bf = bf;
- }
- public void skipLine(){
- try {
- bf.readLine();
- } catch (Exception e) {
- throw new RuntimeException();
- }
- }
- public String nextToken() {
- if(tk==null || !tk.hasMoreTokens()) {
- try {
- tk = new StringTokenizer(bf.readLine(), DELIM);
- } catch (Exception e){
- throw new RuntimeException();
- }
- }
- return tk.nextToken();
- }
- public int nextInt() {
- try {
- return Integer.parseInt(nextToken());
- } catch (Exception e) {
- throw new RuntimeException();
- }
- }
- public long nextLong() {
- try {
- return Long.parseLong(nextToken());
- } catch (Exception e) {
- throw new RuntimeException();
- }
- }
- public double nextDouble() {
- try {
- return Double.parseDouble(nextToken());
- } catch (Exception e) {
- throw new RuntimeException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement