/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 72ms 15.652 MiB
#2 Accepted 110ms 16.133 MiB
#3 Time Exceeded ≥1561ms ≥61.723 MiB
#4 Accepted 1146ms 57.254 MiB
#5 Accepted 784ms 55.516 MiB
#6 Accepted 771ms 59.879 MiB
#7 Accepted 567ms 53.738 MiB
#8 Accepted 631ms 52.195 MiB
#9 Accepted 592ms 49.871 MiB
#10 Accepted 676ms 54.547 MiB
#11 Accepted 591ms 51.77 MiB
#12 Accepted 667ms 51.602 MiB
#13 Accepted 575ms 53.281 MiB
#14 Accepted 569ms 50.043 MiB
#15 Time Exceeded ≥1533ms ≥48.109 MiB

Code

import java.util.*;
import java.io.*;

public class Main {

    static BufferedReader sc;
    static {
        sc = new BufferedReader(new InputStreamReader(System.in));
    }

    public static void main(String[] args)throws IOException {
        int t=Integer.parseInt(sc.readLine());
        PrintWriter out = new PrintWriter(System.out);
        while(t-- > 0){
            String[]arr = sc.readLine().split(" ");
            int n=Integer.parseInt(arr[0]);
            int x=Integer.parseInt(arr[1]);
            int[] a = new int[n];
            int i;
            arr = sc.readLine().split(" ");
            for(i=0;i<n;i++) {a[i]=Integer.parseInt(arr[i]);}
            int q=Integer.parseInt(sc.readLine());
            ArrayList<int[]> al = new ArrayList<>();
            int cx = x;
            for(i=2;i<=100000;i++){
                int ct = 0;
                while (cx%i == 0) {
                    ++ct;
                    cx /= i;
                }
                if (ct > 0) al.add(new int[]{i, ct});
            }
            if(cx > 1) al.add(new int[]{cx,1});
            long[][] pp =new long[al.size()][n];
            for(i=0;i<al.size();i++){
                for(int j=0;j<n;j++){
                    int temp = a[j];
                    int ct = 0;
                    while (temp % al.get(i)[0] == 0){
                        ct++;
                        temp /= al.get(i)[0];
                    }
                    pp[i][j] = ct;
                }
            }

            for(i=0;i<al.size();i++) for(int j=1;j<n;j++) pp[i][j] += pp[i][j-1];

            while (q-- > 0){
                arr = sc.readLine().split(" ");
                int l=Integer.parseInt(arr[0])-1;
                int r=Integer.parseInt(arr[1])-1;
                int ct = 0;
                for(i=0;i<al.size();i++){
                    long sum = pp[i][r] - (l-1>=0  ? pp[i][l-1]:0);
                    if(sum >= al.get(i)[1]) ++ct;
                }
                if(ct == al.size()) out.println("Yes");
                else out.println("No");
            }
            out.flush();
        }
        out.close();
    }
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
Java 8 (OpenJDK 1.8.0_422)
Submit At
2025-03-14 18:35:41
Judged At
2025-03-14 18:35:41
Judged By
Score
53
Total Time
≥1561ms
Peak Memory
≥61.723 MiB