結果

問題 No.435 占い(Extra)
ユーザー chocoruskchocorusk
提出日時 2019-12-02 10:51:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 566 ms / 2,000 ms
コード長 1,338 bytes
コンパイル時間 942 ms
コンパイル使用メモリ 109,184 KB
実行使用メモリ 42,880 KB
最終ジャッジ日時 2024-04-17 03:01:34
合計ジャッジ時間 10,808 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
42,644 KB
testcase_01 AC 65 ms
42,848 KB
testcase_02 AC 63 ms
42,496 KB
testcase_03 AC 64 ms
42,880 KB
testcase_04 AC 64 ms
42,624 KB
testcase_05 AC 62 ms
42,844 KB
testcase_06 AC 67 ms
42,728 KB
testcase_07 AC 64 ms
42,624 KB
testcase_08 AC 64 ms
42,624 KB
testcase_09 AC 64 ms
42,624 KB
testcase_10 AC 67 ms
42,768 KB
testcase_11 AC 66 ms
42,752 KB
testcase_12 AC 105 ms
42,880 KB
testcase_13 AC 97 ms
42,752 KB
testcase_14 AC 90 ms
42,752 KB
testcase_15 AC 86 ms
42,796 KB
testcase_16 AC 112 ms
42,624 KB
testcase_17 AC 401 ms
42,752 KB
testcase_18 AC 107 ms
42,880 KB
testcase_19 AC 98 ms
42,864 KB
testcase_20 AC 566 ms
42,624 KB
testcase_21 AC 484 ms
42,880 KB
testcase_22 AC 398 ms
42,752 KB
testcase_23 AC 329 ms
42,624 KB
testcase_24 AC 284 ms
42,664 KB
testcase_25 AC 523 ms
42,624 KB
testcase_26 AC 559 ms
42,648 KB
testcase_27 AC 479 ms
42,784 KB
testcase_28 AC 65 ms
42,812 KB
testcase_29 AC 484 ms
42,880 KB
testcase_30 AC 559 ms
42,492 KB
testcase_31 AC 447 ms
42,620 KB
testcase_32 AC 391 ms
42,624 KB
testcase_33 AC 313 ms
42,624 KB
testcase_34 AC 376 ms
42,836 KB
testcase_35 AC 339 ms
42,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int f[10000001];
int inv[9]={0, 1, 5, 0, 7, 2, 0, 4, 8};
int main()
{
    f[0]=1;
	for(int i=1; i<=10000000; i++){
		int x=i;
		while(x%3==0){
			x/=3;
		}
		f[i]=f[i-1]*x%9;
	}
	int t;
	cin>>t;
	for(int q=0; q<t; q++){
		int n, x, a, b, m;
		cin>>n>>x>>a>>b>>m;
		int e0=0;
		int n1=n-1;
		while(n1){
			n1/=3;
			e0+=n1;
		}
		bool z=1;
		int s=0;
		for(int i=0; i<n; i++){
			int e=e0;
			int i1=i, i2=n-1-i;
			while(i1){
				i1/=3;
				e-=i1;
			}
			while(i2){
				i2/=3;
				e-=i2;
			}
			if(x%10!=0){
				z=0;
			}
			if(e==0){
				s+=(x%10)*f[n-1]*inv[f[i]]*inv[f[n-1-i]];
				s%=9;
			}else if(e==1){
				s+=(x%10)*f[n-1]*inv[f[i]]*inv[f[n-1-i]]*3;
				s%=9;
			}
			x=(x^a)+b;
			x%=m;
		}
		if(z) printf("0\n");
		else if(s==0) printf("9\n");
		else printf("%d\n", s);
	}
    return 0;
}
0