結果
| 問題 |
No.435 占い(Extra)
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2016-10-19 18:14:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,012 bytes |
| コンパイル時間 | 1,556 ms |
| コンパイル使用メモリ | 159,332 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-08 12:07:23 |
| 合計ジャッジ時間 | 6,454 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 RE * 11 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d", &T);
| ~~~~~^~~~~~~~~~
main.cpp:49:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | scanf("%d %d %d %d %d", &N, &X, &A, &B, &M);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
using ll = long long;
using P = std::tuple<int,int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int S[100100];
int inv[100100];
template <typename T>
T expt(T a, T n, T mod = std::numeric_limits<T>::max()){
T res = 1;
while(n){
if(n & 1){res = res * a % mod;}
a = a * a % mod;
n >>= 1;
}
return res;
}
int main(){
//*
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
/*/
/*/
for(int i=1;i<=100000;++i){
// generate inv
if(i == 1 || i % 3 == 0){inv[i] = 1;}
else{
inv[i] = expt(i % 9, 5, 9);
}
}
int T;
scanf("%d", &T);
for(int _=0;_<T;++_){
int N, X, A, B, M;
scanf("%d %d %d %d %d", &N, &X, &A, &B, &M);
S[0] = X;
for(int i=1;i<N;++i){
S[i] = ((S[i-1] ^ A) + B) % M;
}
for(int i=0;i<N;++i){
S[i] %= 10;
}
int l = N, n = l - 1;
if(count(S, S+l, 0) == l){
puts("0");
continue;
}
int three_n = 0, m = 1;
int res = 0;
for(int i=0;i<=n;++i){
if(i >= 1){
int x = i;
while(x % 3 == 0){
--three_n;
x /= 3;
}
m = m * inv[x] % 9;
x = n - i + 1;
while(x % 3 == 0){
++three_n;
x /= 3;
}
m = m * x % 9;
}
int a = S[i], three_n2 = three_n + (a % 3 == 0) + (a % 9 == 0);
if(three_n2 < 2){
res = (res + a * m % 9 * expt(3, three_n) % 9) % 9;
}
}
printf("%d\n", res > 0 ? res : 9);
}
}
tottoripaper