結果
| 問題 |
No.435 占い(Extra)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-02 18:57:20 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,737 bytes |
| コンパイル時間 | 3,786 ms |
| コンパイル使用メモリ | 78,460 KB |
| 実行使用メモリ | 77,516 KB |
| 最終ジャッジ日時 | 2024-10-08 12:19:03 |
| 合計ジャッジ時間 | 14,383 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | MLE * 4 |
| other | MLE * 32 |
ソースコード
package yukicoder;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
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 = Integer.parseInt(sc.next());
int x = Integer.parseInt(sc.next());
int a = Integer.parseInt(sc.next());
int b = Integer.parseInt(sc.next());
int m = Integer.parseInt(sc.next());
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();
sc.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;
}
@SuppressWarnings("unused")
private static class Scanner {
BufferedReader br;
Iterator<String> it;
Scanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
String next() throws RuntimeException {
try {
if (it == null || !it.hasNext()) {
it = Arrays.asList(br.readLine().split(" ")).iterator();
}
return it.next();
} catch (IOException e) {
throw new IllegalStateException();
}
}
int nextInt() throws RuntimeException {
return Integer.parseInt(next());
}
long nextLong() throws RuntimeException {
return Long.parseLong(next());
}
float nextFloat() throws RuntimeException {
return Float.parseFloat(next());
}
double nextDouble() throws RuntimeException {
return Double.parseDouble(next());
}
void close() {
try {
br.close();
} catch (IOException e) {
// throw new IllegalStateException();
}
}
}
}