結果

問題 No.6 使いものにならないハッシュ
ユーザー goodbaton
提出日時 2014-11-23 16:56:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,472 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 70,252 KB
実行使用メモリ 13,768 KB
最終ジャッジ日時 2025-01-02 20:22:12
合計ジャッジ時間 92,017 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23 TLE * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |     scanf("%d%d",&k,&n);
      |     ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

bool so[200010];
int syaku[2][100000];

void sosu(){
    so[0]=so[1]=true;
    for(int i=2;i<=200000;i++){
        if(!so[i])
            for(int j=2;j*i<=200000;j++){
                so[j*i]=true;
            }
    }
}

int Hash(int num){
    int re=0,p,k=log10(num);
    for(int i=k;i>=0;i--){
        p = pow(10,i);
        re+=num/p;
        num=num%p;
    }
    if(re>=10)
        return Hash(re);
    else
        return re;
}

int main(){
    int k,n,j,l=0,r=0,ch[10],max_lr=-1,max_s=0;
    sosu();
    
    scanf("%d%d",&k,&n);
    
    j=0;
    for(int i=k;i<=n;i++){
        if(!so[i]){
            syaku[0][j]=Hash(i);
            syaku[1][j]=i;
            j++;
        }
    }
    
    //shakutori
    while(r<=j){
        if(max_lr<=r-l){
            max_lr=r-l;
            max_s=syaku[1][l];
        }
        
        for(int i=l;i<=r;i++){
            if(ch[syaku[0][i]]){
                l++;
                break;
            }
            ch[syaku[0][i]]=1;
            if(i==r){
                r++;
                break;
            }
        }
        for(int i=0;i<10;i++){
            ch[i]=0;
        }
        
    }
    
    printf("%d\n",max_s);
    
    
    return 0;
}
0