結果

問題 No.1006 Share an Integer
ユーザー 👑 jupirojupiro
提出日時 2020-03-06 21:47:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 538 ms / 2,000 ms
コード長 2,873 bytes
コンパイル時間 1,293 ms
コンパイル使用メモリ 119,124 KB
実行使用メモリ 63,920 KB
最終ジャッジ日時 2023-08-04 08:56:27
合計ジャッジ時間 9,631 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 176 ms
52,880 KB
testcase_01 AC 175 ms
52,536 KB
testcase_02 AC 174 ms
52,980 KB
testcase_03 AC 172 ms
52,720 KB
testcase_04 AC 171 ms
52,608 KB
testcase_05 AC 185 ms
53,288 KB
testcase_06 AC 181 ms
52,280 KB
testcase_07 AC 187 ms
53,632 KB
testcase_08 AC 178 ms
52,256 KB
testcase_09 AC 180 ms
52,312 KB
testcase_10 AC 180 ms
53,600 KB
testcase_11 AC 367 ms
56,800 KB
testcase_12 AC 521 ms
62,768 KB
testcase_13 AC 538 ms
63,920 KB
testcase_14 AC 536 ms
63,852 KB
testcase_15 AC 490 ms
61,452 KB
testcase_16 AC 312 ms
54,536 KB
testcase_17 AC 365 ms
56,908 KB
testcase_18 AC 477 ms
61,456 KB
testcase_19 AC 457 ms
60,936 KB
testcase_20 AC 488 ms
61,992 KB
testcase_21 AC 523 ms
63,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;



bool IsPrime[MAX];
ll MinFactor[MAX]; vector<ll> preprocess(ll n = MAX) {
    vector<ll> res;
    for (ll i = 0; i < n; ++i) IsPrime[i] = true, MinFactor[i] = -1;
    IsPrime[0] = false; IsPrime[1] = false;
    MinFactor[0] = 0; MinFactor[1] = 1;
    for (ll i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            MinFactor[i] = i;
            res.push_back(i);
            for (ll j = i * 2; j < n; j += i) {
                IsPrime[j] = false;
                if (MinFactor[j] == -1) MinFactor[j] = i;
            }
        }
    }
    return res;
}

vector<pair<ll, ll> > fast_prime_factor(ll n) {
    vector<pair<ll, ll> > res;
    while (n != 1) {
        ll prime = MinFactor[n];
        ll exp = 0;
        while (MinFactor[n] == prime) {
            ++exp;
            n /= prime;
        }
        res.push_back(make_pair(prime, exp));
    }
    return res;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
    preprocess();
    ll X; scanf("%lld", &X);
    if (X == 2) {
        cout << "1 1" << endl;
        return 0;
    }
    vector<pair<ll, ll>> res;
    ll ans = INF;
    vector<ll> cnt(X + 1, 1);
    for (int i = 1; i <= X; i++) {
        vector<pair<ll,ll>> vp = fast_prime_factor(i);
        for (auto p : vp) {
            cnt[i] *= (p.second + 1);
        }

    }
    for (ll a = 1; a < X; a++) {
        ll b = X - a;
        ll cnt1 = cnt[a], cnt2 = cnt[b];
        ll res1 = a - cnt1;
        ll res2 = b - cnt2;
        chmin(ans, llabs(res1 - res2));
    }
    for (ll a = 1; a < X; a++) {
        ll b = X - a;
        ll cnt1 = cnt[a], cnt2 = cnt[b];

        ll res1 = a - cnt1;
        ll res2 = b - cnt2;
        if (llabs(res1 - res2) == ans) {
            res.emplace_back(a, b);
        }
    }
    for (int i = 0; i < res.size(); i++) {
        printf("%lld %lld\n", res[i].first, res[i].second);
    }
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0