結果

問題 No.6 使いものにならないハッシュ
ユーザー monnumonnu
提出日時 2020-07-05 20:51:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,152 bytes
コンパイル時間 1,767 ms
コンパイル使用メモリ 171,132 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-14 23:25:20
合計ジャッジ時間 3,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,368 KB
testcase_01 AC 3 ms
4,372 KB
testcase_02 AC 4 ms
4,368 KB
testcase_03 AC 3 ms
4,372 KB
testcase_04 AC 3 ms
4,368 KB
testcase_05 AC 4 ms
4,372 KB
testcase_06 AC 4 ms
4,372 KB
testcase_07 AC 4 ms
4,368 KB
testcase_08 AC 4 ms
4,368 KB
testcase_09 AC 3 ms
4,372 KB
testcase_10 AC 3 ms
4,372 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 4 ms
4,368 KB
testcase_13 AC 3 ms
4,372 KB
testcase_14 AC 3 ms
4,368 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 3 ms
4,372 KB
testcase_17 AC 4 ms
4,372 KB
testcase_18 AC 5 ms
4,372 KB
testcase_19 AC 4 ms
4,368 KB
testcase_20 AC 4 ms
4,372 KB
testcase_21 AC 3 ms
4,368 KB
testcase_22 AC 4 ms
4,372 KB
testcase_23 AC 4 ms
4,372 KB
testcase_24 AC 3 ms
4,368 KB
testcase_25 AC 4 ms
4,368 KB
testcase_26 AC 4 ms
4,372 KB
testcase_27 AC 4 ms
4,372 KB
testcase_28 AC 4 ms
4,368 KB
testcase_29 AC 4 ms
4,368 KB
testcase_30 AC 4 ms
4,372 KB
testcase_31 AC 4 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
using pp=pair<int,pair<int,int>>;
#define MOD 1000000007
#define INF 1000000000

#define MAX 200003
vector<int> p;
vector<bool> p_table(MAX+1,true);
void prime(){
  p_table.at(0)=false,p_table.at(1)=false;
  for(int i=2;i<=MAX;i++){
    if(p_table.at(i)){
      p.push_back(i);
      for(int j=2;i*j<=MAX;j++){
        p_table.at(i*j)=false;
      }
    }
  }
}


int main(){
  int K,N;
  cin>>K>>N;
  vector<int> a;
  prime();
  for(int i=K;i<=N;i++){
    if(p_table.at(i)){
      a.push_back(i);
    }
  }

  int n=a.size();
  vector<int> b(n);
  for(int i=0;i<n;i++){
    b.at(i)=a.at(i);
    while(b.at(i)>=10){
      int num=0;
      while(b.at(i)>0){
        num+=b.at(i)%10;
        b.at(i)/=10;
      }
      b.at(i)=num;
    }
  }

  int l=0;
  int index=0;
  for(int i=0;i<n;i++){
    int j=i;
    vector<bool> have(10,false);
    while(have.at(b.at(j))==false){
      have.at(b.at(j))=true;
      j++;
      if(j==n){
        break;
      }
    }
    if(j-i>=l){
      l=j-i;
      index=i;
    }
  }

  cout<<a.at(index)<<endl;;
}
0