結果

問題 No.6 使いものにならないハッシュ
ユーザー ttkkggwwttkkggww
提出日時 2022-03-08 11:00:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,242 bytes
コンパイル時間 7,400 ms
コンパイル使用メモリ 264,760 KB
実行使用メモリ 4,960 KB
最終ジャッジ日時 2023-09-30 16:35:32
合計ジャッジ時間 6,443 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 9 ms
4,872 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 5 ms
4,384 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 5 ms
4,388 KB
testcase_09 AC 5 ms
4,508 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 6 ms
4,412 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 5 ms
4,612 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 5 ms
4,656 KB
testcase_17 AC 7 ms
4,780 KB
testcase_18 AC 8 ms
4,812 KB
testcase_19 AC 6 ms
4,960 KB
testcase_20 AC 6 ms
4,696 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 6 ms
4,700 KB
testcase_23 AC 6 ms
4,412 KB
testcase_24 AC 6 ms
4,488 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 7 ms
4,772 KB
testcase_27 AC 6 ms
4,784 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 7 ms
4,872 KB
testcase_30 AC 6 ms
4,604 KB
testcase_31 AC 6 ms
4,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;

int l,r;

vector<long long> primes(long long n){
	vector<long long> res;
	vector<long long> is(n);
	for(int i = 2;i<n;i++){
		if(is[i]==0){
			for(int j = i*2;j<n;j+=i){
				is[j] = 1;
			}
		}
	}
	for(int i = max(2,l);i<n;i++){
		if(is[i]==0){
			res.push_back(i);
		}
	}
	return res;
}

ll f(ll x){
	while(x>9){
		ll y = 0;
		while(x){
			y+= x%10;
			x/=10;
		}
		x= y;
	}
	return x;
}

void solve(){
	auto v = primes(r+1);
	vector<ll> fv;
	for(auto &i:v)fv.push_back(f(i));
	ll mxlen = 1,mxnum = 0;
	ll cur = fv[0];
	//for(int i = 0;i<v.size();i++)cout<<v[i]<<' '<<fv[i]<<endl;
	for(int i = 0;i<v.size();i++){
		set<ll> st;
		for(int j = i;j<v.size();j++){
			if(st.count(fv[j])){
				if(st.size()>=mxlen){
					mxlen = st.size();
					cur = v[i];
					//cout<<':'<<v[i]<<endl;
					//for(auto &k:st)cout<<k<<endl;
					st.clear();
				}
				break;
			}
			st.insert(fv[j]);
		}
		if(st.size()){
			if(st.size()>=mxlen){
				mxlen = st.size();
				cur = v[i];
				st.clear();
			}
		}
	}
	//cout<<mxlen<<endl;
	cout<<cur<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> l >> r;
	solve();
}
0