結果

問題 No.6 使いものにならないハッシュ
ユーザー CleyLCleyL
提出日時 2021-11-21 00:50:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 899 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 85,108 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 14:09:52
合計ジャッジ時間 2,823 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 31 ms
4,380 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 16 ms
4,380 KB
testcase_07 AC 10 ms
4,376 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 24 ms
4,380 KB
testcase_18 AC 28 ms
4,376 KB
testcase_19 AC 23 ms
4,380 KB
testcase_20 AC 19 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 21 ms
4,380 KB
testcase_23 AC 18 ms
4,380 KB
testcase_24 AC 20 ms
4,380 KB
testcase_25 AC 11 ms
4,376 KB
testcase_26 AC 25 ms
4,376 KB
testcase_27 AC 18 ms
4,376 KB
testcase_28 AC 11 ms
4,376 KB
testcase_29 AC 26 ms
4,380 KB
testcase_30 AC 22 ms
4,376 KB
testcase_31 AC 20 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <set>
using namespace std;
int digitsum(string x){
  int nw = 0;
  for(int i = 0; x.size() > i; i++){
    nw += x[i]-'0';
  }
  if(nw < 10){
    return nw;
  }else {
    return digitsum(to_string(nw));
  }
}
bool isPrime(int x){
  if(x == 1)return false;
  for(int i = 2; x >= i*i; i++){
    if(!(x%i))return false;
  }
  return true;
}
int main(){
  int k,n;cin>>k>>n;
  queue<int> nw;
  set<int> x;
  int ans = 0;
  int ansp = -1;
  for(int i = k; n >= i; i++){
    if(isPrime(i)){
      int t = digitsum(to_string(i));
      while(x.count(t)){
        int z = nw.front();nw.pop();
        x.erase(digitsum(to_string(z)));
      }
      x.insert(t);
      nw.push(i);
      if(nw.size() > ans){
        ans = nw.size();
        ansp = nw.front();
      }else if(nw.size() == ans){
        ansp = nw.front();
      }
    }
  }
  cout << ansp << endl;
}
0