結果

問題 No.6 使いものにならないハッシュ
ユーザー roaiziroroaiziro
提出日時 2015-09-30 12:17:28
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,760 bytes
コンパイル時間 886 ms
コンパイル使用メモリ 25,616 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 22:55:43
合計ジャッジ時間 1,708 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<stdio.h>


#define N 200001
#define HN 18000
#define HS 10

struct HASHNODE{
    int p, h;
}hashnode[HN];
int noden;
int nemu[N], prime[N], hashtable[HS];

int hash(int n)
{
    int h = 0, mod;
    while(0 < n){
        mod = n % 10;
        h += mod;
        n /= 10;
    }
    if(10 <= h){
        h = hash(h);
    }
    return(h);
}

int p(int n)
{
    int i, j;
    
    for(i = 1; i <= n; i++){
        nemu[i] = i;
    }
    nemu[1] = 0;
    for(i = 2; i*i <= n; i++){
        for(j = i; i*j <= n; j++){
            nemu[i*j] = 0;
        }
    }
    return(0);
}

int hashnodecreate(int k, int n)
{
    noden = 1;
    while(k <= n){
        if(nemu[k]){
            hashnode[noden].p = nemu[k];
            hashnode[noden].h = hash(nemu[k]);
            noden++;
        }
        k++;
    }
    return(noden);
}

void cmb(void)
{
    int i, j, k, w[HS];
    for(i = 1; i < noden; i++){
        for(k = 1; k < HS; k++){
            w[k] = 0;
        }
        for(j = i; j < noden; j++){
            if(w[hashnode[j].h] == 0){
                w[hashnode[j].h] = 1;
            }else{
                break;
            }
        }
        if(hashnode[hashtable[j - i]].p < hashnode[i].p){
            hashtable[j - i] = i;
        }
    }
    return;
}

void ans(void)
{
    int i;
    for(i = HS-1; 0 < i; i--){
        if(hashtable[i]){
            printf("%d\n", hashnode[hashtable[i]].p);
            break;
        }
    }
}

int main(int argc, const char * argv[])
{
    int k, n, i, j;
    scanf("%d", &k);
    scanf("%d", &n);
    p(n);
    j = hashnodecreate(k, n);
//    for(i = 1; i < j; i++){
//        printf("p=%d hash=%d\n", hashnode[i].p, hashnode[i].h);
//    }
//    printf("j=%d\n", j);
    cmb();
    ans();
    return 0;
}
0