/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 73ms 15.719 MiB
#2 Wrong Answer 121ms 17.543 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:30:06
Judged At
2025-03-14 18:30:06
Judged By
Score
0
Total Time
121ms
Peak Memory
17.543 MiB