結果

問題 No.434 占い
ユーザー 👑 kmjpkmjp
提出日時 2016-10-14 23:46:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 1,406 bytes
コンパイル時間 1,374 ms
コンパイル使用メモリ 149,980 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-08-14 10:53:34
合計ジャッジ時間 4,092 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 3 ms
4,520 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 16 ms
4,376 KB
testcase_13 AC 15 ms
4,572 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 124 ms
4,688 KB
testcase_16 AC 82 ms
4,380 KB
testcase_17 AC 57 ms
4,380 KB
testcase_18 AC 24 ms
4,376 KB
testcase_19 AC 25 ms
4,380 KB
testcase_20 AC 137 ms
4,460 KB
testcase_21 AC 280 ms
4,888 KB
testcase_22 AC 125 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 82 ms
4,408 KB
testcase_25 AC 122 ms
4,620 KB
testcase_26 AC 181 ms
4,440 KB
testcase_27 AC 56 ms
4,380 KB
testcase_28 AC 51 ms
4,380 KB
testcase_29 AC 36 ms
4,408 KB
testcase_30 AC 109 ms
4,380 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 = 200000;
int NP,prime[100000],divp[prime_max];

void cprime() {
	for(int i=2;i<prime_max;i++) if(divp[i]==0) {
		prime[NP++]=i;
		divp[i]=i;
		for(ll j=1LL*i*i;j>i&&j<prime_max;j+=i) divp[j]=i;
	}
}

int T;
string S;
void solve() {
	int i,j,k,l,r,x,y; string s;
	cprime();
	
	cin>>T;
	while(T--) {
		cin>>S;
		ll ret=0;
		
		multiset<int> M;
		
		for(i=0;i<S.size();i++) {
			
			x = 1;
			FORR(r,M) {
				x=x*r%9;
				if(x==0) break;
			}
			if(x==0) x=9;
			ret += (S[i]-'0')*x;
			
			if(i<S.size()-1) {
				x = S.size()-1-i;
				y = 1+i;
				while(divp[x]) M.insert(divp[x]), x /= divp[x];
				while(divp[y]) M.erase(M.find(divp[y])), y /= divp[y];
			}
		}
		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