結果

問題 No.435 占い(Extra)
ユーザー 👑 kmjpkmjp
提出日時 2016-10-15 00:04:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,464 ms / 2,000 ms
コード長 1,556 bytes
コンパイル時間 1,324 ms
コンパイル使用メモリ 160,892 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-04-17 02:38:59
合計ジャッジ時間 22,411 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
22,784 KB
testcase_01 AC 103 ms
22,784 KB
testcase_02 AC 115 ms
22,784 KB
testcase_03 AC 95 ms
22,912 KB
testcase_04 AC 111 ms
22,912 KB
testcase_05 AC 123 ms
22,784 KB
testcase_06 AC 126 ms
22,912 KB
testcase_07 AC 114 ms
22,912 KB
testcase_08 AC 116 ms
22,912 KB
testcase_09 AC 111 ms
22,784 KB
testcase_10 AC 130 ms
22,912 KB
testcase_11 AC 131 ms
22,912 KB
testcase_12 AC 219 ms
22,912 KB
testcase_13 AC 204 ms
22,784 KB
testcase_14 AC 210 ms
22,912 KB
testcase_15 AC 161 ms
22,912 KB
testcase_16 AC 171 ms
22,912 KB
testcase_17 AC 321 ms
22,912 KB
testcase_18 AC 235 ms
22,912 KB
testcase_19 AC 217 ms
22,912 KB
testcase_20 AC 1,292 ms
22,784 KB
testcase_21 AC 1,091 ms
22,912 KB
testcase_22 AC 997 ms
22,912 KB
testcase_23 AC 973 ms
22,912 KB
testcase_24 AC 508 ms
22,912 KB
testcase_25 AC 640 ms
22,912 KB
testcase_26 AC 1,296 ms
22,912 KB
testcase_27 AC 1,464 ms
22,912 KB
testcase_28 AC 105 ms
22,912 KB
testcase_29 AC 1,062 ms
22,912 KB
testcase_30 AC 1,293 ms
22,784 KB
testcase_31 AC 1,150 ms
22,784 KB
testcase_32 AC 1,001 ms
22,912 KB
testcase_33 AC 1,214 ms
22,912 KB
testcase_34 AC 1,257 ms
22,912 KB
testcase_35 AC 1,227 ms
22,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

const int prime_max = 10000001;
short divp[prime_max];

void cprime() {
	for(int i=2;i<prime_max;i++) if(divp[i]==0) {
		for(ll j=1LL*i*i;j>i&&j<prime_max;j+=i) divp[j]=i;
	}
}
ll modpow(ll a, ll n, ll mo) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

int T;
int N,X,A,B,M;
int num[12];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cprime();
	cin>>T;
	while(T--) {
		cin>>N>>X>>A>>B>>M;
		
		ll ret=0;
		
		ZERO(num);
		
		
		for(i=0;i<N;i++) {
			
			if(num[3]<2) {
				x = 1;
				for(j=2;j<=8;j++) x = x*modpow(j,num[j],9);
				ret += x*(X%10);
			}
			else {
				ret += 9*(X%10);
			}
			
			
			if(i<N-1) {
				x = N-1-i;
				y = 1+i;
				while(divp[x]) num[divp[x]%9]++, x /= divp[x];
				num[x%9]++;
				while(divp[y]) num[divp[y]%9]--, y /= divp[y];
				num[y%9]--;
			}
			
			X = ((X^A)+B)%M;
		}
		while(ret>=10) ret=ret%10+ret/10;
		
		cout<<ret<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0