結果

問題 No.6 使いものにならないハッシュ
ユーザー Ai3ShotaAi3Shota
提出日時 2018-05-25 17:24:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 975 bytes
コンパイル時間 1,105 ms
コンパイル使用メモリ 147,652 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:11:55
合計ジャッジ時間 3,092 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int N, K;
vector<int> prime;
bool used[10];
int dp[10] = {0};

void Prime(){
    int i, j, k;
    if(K <= 2) prime.push_back(2);
	for(i = 3; i <= 200000; i += 2){
		k = 0;
		for(j = 3; j <= sqrt(i); j += 2){
			if(i % j == 0){
				k = 1;
				break;
			}
		}
		if(k == 0 && K <= i && i <= N) prime.push_back(i);
	}
	return;
}

int Hash(int num){
    int res = 0;
	while (num > 0){
		res += num % 10;
		num /= 10;
	}
	if (res >= 10) return Hash(res);
	return res;
}

int main(void){
    
    cin >> K >> N;
    
    Prime();
    
    int j = 0, p_head = 0, p_len = 0;
    for(int i = 0; i < prime.size(); ++i){
        int i_h = Hash(prime[i]);
        ++dp[i_h];
        while(dp[i_h] > 1){
            int j_h = Hash(prime[j++]);
            --dp[j_h];
        }
        if(i - j + 1 >= p_len){
            p_head = prime[j];
            p_len = i - j + 1;
        }
    }
    
    cout << p_head << endl;
    
    return 0;
}
0