結果

問題 No.434 占い
ユーザー 👑 kmjpkmjp
提出日時 2016-10-14 23:30:07
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,572 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 166,000 KB
実行使用メモリ 14,540 KB
最終ジャッジ日時 2024-05-01 22:50:29
合計ジャッジ時間 5,618 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
14,540 KB
testcase_01 AC 9 ms
7,552 KB
testcase_02 AC 9 ms
7,552 KB
testcase_03 AC 9 ms
7,552 KB
testcase_04 AC 9 ms
7,552 KB
testcase_05 AC 10 ms
7,552 KB
testcase_06 AC 11 ms
7,552 KB
testcase_07 AC 10 ms
7,524 KB
testcase_08 AC 58 ms
7,736 KB
testcase_09 AC 21 ms
7,552 KB
testcase_10 AC 13 ms
7,424 KB
testcase_11 AC 11 ms
7,552 KB
testcase_12 AC 24 ms
7,552 KB
testcase_13 AC 56 ms
7,644 KB
testcase_14 AC 20 ms
7,552 KB
testcase_15 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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))
//-------------------------------------------------------

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

const int prime_max = 1000000;
int NP,prime[100000],divp[prime_max];
map<int,int> M;

void cprime() {
	for(int i=2;i<prime_max;i++) if(divp[i]==0) {
		//M[i]=NP;
		prime[NP++]=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;
			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];
				}
				if(x>1) M.insert(x);
				while(divp[y]) {
					M.erase(M.find(divp[y]));
					y /= divp[y];
				}
				if(y>1) M.erase(M.find(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