結果
| 問題 | No.2709 1975 Powers | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2024-04-01 16:08:47 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 448 ms / 2,000 ms | 
| コード長 | 2,473 bytes | 
| コンパイル時間 | 2,125 ms | 
| コンパイル使用メモリ | 79,384 KB | 
| 実行使用メモリ | 41,936 KB | 
| 最終ジャッジ日時 | 2024-09-30 21:53:08 | 
| 合計ジャッジ時間 | 8,186 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 25 | 
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
    static int p;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] base = new int[]{10, 9, 7, 5};
        p = sc.nextInt();
        int q = sc.nextInt();
        int[] tmp = new int[n];
        for (int i = 0; i < n; i++) {
            tmp[i] = sc.nextInt();
        }
        Arrays.sort(tmp);
        int[][] values = new int[n][4];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 4; j++) {
                values[i][j] = pow(base[j], tmp[i]);
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int current1 = values[i][0];
            for (int j = i + 1; j < n; j++) {
                int current2 = (current1 + values[j][1]) % p;
                for (int k = j + 1; k < n; k++) {
                    int current3 = (current2 + values[k][2]) % p;
                    for (int l = k + 1; l < n; l++) {
                        int current4 = (current3 + values[l][3]) % p;
                        if (current4 == q) {
                            ans++;
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }
    static int pow(int x, int pp) {
        if (pp == 0) {
            return 1;
        } else if (pp % 2 == 0) {
            return pow((int)((long)x * x % p), pp / 2);
        } else {
            return (int)((long)pow(x, pp - 1) * x % p);
        }
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
            
            
            
        