結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-04-17 20:28:44 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 88 ms / 5,000 ms | 
| コード長 | 1,328 bytes | 
| コンパイル時間 | 707 ms | 
| コンパイル使用メモリ | 92,160 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-16 16:49:20 | 
| 合計ジャッジ時間 | 2,775 ms | 
| ジャッジサーバーID (参考情報) | judge6 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
ソースコード
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>
ll a, b, ma = 0, ans;
vector<ll> prime, h;
bool IsPrime(ll n) {
	if (n <= 1)return false;
	for (ll i = 2; i <= sqrt(n); i++)
	{
		if (n % i == 0)return false;
	}
	return true;
}
int hs(ll a) {
	ll res = a;
	while (res > 9) {
		ll next = 0;
		while (res > 0) {
			next += res % 10;
			res /= 10;
		}
		res = next;
	}
	return res;
}
int main() {
	cin >> a >> b;
	FOR(i, a, b + 1)if (IsPrime(i))prime.push_back(i);
	REP(i, prime.size())h.push_back(hs(prime[i]));
	REPR(i, h.size() - 1) {
		ll now = 0;
		set<ll> se;
		FOR(j, i, h.size()) {
			if (se.find(h[j]) != se.end())break;
			else {
				se.insert(h[j]);
				now++;
			}
		}
		if (ma < now) {
			ma = now;
			ans = prime[i];
		}
	}
	
	
	cout << ans << endl;
}
            
            
            
        