結果

問題 No.1006 Share an Integer
ユーザー koi_kotyakoi_kotya
提出日時 2020-03-06 22:05:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,166 ms / 2,000 ms
コード長 1,485 bytes
コンパイル時間 1,763 ms
コンパイル使用メモリ 169,376 KB
実行使用メモリ 11,152 KB
最終ジャッジ日時 2024-04-22 07:52:10
合計ジャッジ時間 12,715 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,948 KB
testcase_06 AC 2 ms
6,948 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 560 ms
7,648 KB
testcase_12 AC 1,074 ms
10,560 KB
testcase_13 AC 1,165 ms
11,152 KB
testcase_14 AC 1,166 ms
11,104 KB
testcase_15 AC 952 ms
9,884 KB
testcase_16 AC 390 ms
6,940 KB
testcase_17 AC 583 ms
7,652 KB
testcase_18 AC 962 ms
9,932 KB
testcase_19 AC 932 ms
9,500 KB
testcase_20 AC 1,012 ms
10,144 KB
testcase_21 AC 1,145 ms
11,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

int const MAX_N = 2000;
vector<ll> prime;
vector<bool> is_prime(MAX_N,true);
void Eratosthenes() {
    is_prime[0] = is_prime[1] = false;
    for (ll i = 2;i*i < MAX_N;++i) if (is_prime[i]) for (ll j = 2*i;j < MAX_N;j += i) is_prime[j] = false;
    for (ll i = 0;i < MAX_N;++i) if (is_prime[i]) prime.push_back(i);
}

int main() {
    Eratosthenes();
    int x;
    cin >> x;
    vector<int> a(x+1,1);
    for (int i = 1;i < x+1;++i) {
        int j = i;
        for (ll& p : prime) {
            if (p*p > j) break;
            if (j%p) continue;
            int cnt = 1;
            while (j%p == 0) j /= p,cnt++;
            a[i] *= cnt;
        }
        if (j > 1) a[i] *= 2;
    }
    int mn = 1e9;
    for (int i = 1;i < x/2+1;++i) mn = min(mn,abs((i-a[i])-(x-i-a[x-i])));
    for (int i = 1;i < x+1;++i) if (abs((i-a[i])-(x-i-a[x-i])) == mn) cout << i << " " << x-i << "\n";
}
0