結果
| 問題 |
No.435 占い(Extra)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-02 18:46:41 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,577 bytes |
| コンパイル時間 | 4,005 ms |
| コンパイル使用メモリ | 77,104 KB |
| 実行使用メモリ | 76,748 KB |
| 最終ジャッジ日時 | 2024-10-08 12:19:33 |
| 合計ジャッジ時間 | 20,494 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 MLE * 6 |
ソースコード
package yukicoder;
import java.io.PrintWriter;
import java.util.Scanner;
public class Q435 {
static final int[] inv = new int[] { 0, 1, 5, 0, 7, 2, 0, 4, 8 };
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter pw=new PrintWriter(System.out);
int T = sc.nextInt();
while (T-- > 0) {
int n = sc.nextInt();
int x = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
int m = sc.nextInt();
int reducedCombi = 1;
int count3 = 0;
int ans = 0;
boolean f = true;
int cur = x;
for (int i = 0; i < n; ++i) {
int combi = reducedCombi;
if (i > 0) {
cur = next(n, cur, a, b, m);
reducedCombi = reducedCombi * inv[reduce3(i) % 9] * reduce3(n - 1 - i + 1) % 9;
count3 = count3 - count3(i) + count3(n - 1 - i + 1);
if (count3 >= 2) {
combi = 0;
} else if (count3 == 1) {
combi = 3 * reducedCombi % 9;
} else if (count3 == 0) {
combi = reducedCombi % 9;
} else if (count3 < 0) {
throw new AssertionError();
}
}
ans = (ans + combi * (cur % 10)) % 9;
if (f)
if (cur % 10 > 0)
f = false;
}
if (f)
pw.println(0);
else if (!f && ans == 0)
pw.println(9);
else
pw.println(ans);
}
pw.close();
}
static int count3(int n) {
int c = 0;
while (n > 0 && n % 3 == 0) {
n /= 3;
++c;
}
return c;
}
static int reduce3(int n) {
while (n > 0 && n % 3 == 0)
n /= 3;
return n;
}
static int next(int n, int cur, int a, int b, int m) {
return ((cur ^ a) + b) % m;
}
}