結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-06 23:51:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,001 bytes |
| コンパイル時間 | 2,273 ms |
| コンパイル使用メモリ | 203,840 KB |
| 最終ジャッジ日時 | 2025-02-21 11:29:45 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int L,R; cin >> L >> R;
int Need = R;
vector<bool> prime(Need+1,true);
prime.at(0) = false; prime.at(1) = false;
for(int i=2; i*i<=Need; i++){
if(!prime.at(i)) continue;
for(int k=i*i; k<=Need; k+=i) prime.at(k) = false;
}
vector<int> P;
for(int i=L; i<=R; i++) if(prime.at(i)) P.push_back(i);
int anslen = 0,ansp = -1;
vector<bool> already(10);
queue<pair<int,int>> Q;
for(auto p : P){
int num = p;
while(p >= 10){
int next = 0;
while(p) next += p%10,p /= 10;
p = next;
}
while(already.at(p)){
auto[ign,p2] = Q.front(); Q.pop();
already.at(p2) = false;
}
already.at(p) = true; Q.push({num,p});
if(Q.size() >= anslen) anslen = Q.size(),ansp = Q.front().first;
}
cout << ansp << endl;
}