結果

問題 No.435 占い(Extra)
ユーザー 👑 kmjpkmjp
提出日時 2016-10-14 23:56:41
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,443 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 164,720 KB
実行使用メモリ 30,336 KB
最終ジャッジ日時 2024-04-17 02:37:43
合計ジャッジ時間 6,617 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
28,288 KB
testcase_01 AC 88 ms
22,912 KB
testcase_02 AC 77 ms
22,860 KB
testcase_03 AC 90 ms
22,744 KB
testcase_04 AC 83 ms
22,824 KB
testcase_05 AC 85 ms
22,872 KB
testcase_06 AC 81 ms
22,908 KB
testcase_07 AC 85 ms
22,868 KB
testcase_08 AC 98 ms
22,748 KB
testcase_09 AC 96 ms
22,852 KB
testcase_10 AC 199 ms
23,168 KB
testcase_11 AC 146 ms
22,784 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
	}
}

int T;
int N,X,A,B,M;
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;
		
		multiset<int> MM;
		
		for(i=0;i<N;i++) {
			x = 1;
			FORR(r,MM) {
				x=x*r%9;
				if(x==0) break;
			}
			if(x==0) x=9;
			ret += x*(X%10);
			
			if(i<N-1) {
				x = N-1-i;
				y = 1+i;
				while(divp[x]) MM.insert(divp[x]), x /= divp[x];
				if(x>1) MM.insert(x);
				while(divp[y]) MM.erase(MM.find(divp[y])), y /= divp[y];
				if(y>1) MM.erase(MM.find(y));
			}
			
			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