結果

問題 No.1058 素敵な数
ユーザー tarattata1tarattata1
提出日時 2020-05-22 22:21:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,998 bytes
コンパイル時間 830 ms
コンパイル使用メモリ 91,792 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 17:19:45
合計ジャッジ時間 1,338 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,948 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

vector<int> pp;
void preparePrime( int maxp )
{
    int i;
    vector<int> a(maxp+1);
    for(i=2; i<=maxp; i++) {
        int k=i+i;
        while(k<=maxp) {
            a[k]=1;
            k+=i;
        }
    }
    for(i=2; i<=maxp; i++) {
        if(a[i]==0) pp.push_back( i );
    }
    return;
}

void solve()
{
    int n;
    scanf("%d", &n);
    if (n == 1) {
        printf("1\n"); return;
    }
    
    vector<ll> v;
    preparePrime(1000);
    int i,j;
    for (i = 100001; i < 100200; i++) {
        int flag = 0;
        for (j = 0; j < (int)pp.size(); j++) {
            if (i%pp[j] == 0) {
                flag = 1;
                break;
            }
        }
        if (flag == 0) {
            v.push_back(i);
            if ((int)v.size() == 10)
                break;
        }
    }
    set<ll> s;
    for (i = 0; i < 10; i++) {
        for (j = i; j < 10; j++) {
            s.insert(v[i] * v[j]);
        }
    }
    int cnt = 1;
    auto it = s.begin();
    for (; it != s.end(); ++it) {
        cnt++;
        if (cnt == n) {
            printf("%lld\n", *it); return;
        }
    }

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}
0