結果

問題 No.1006 Share an Integer
ユーザー chocoruskchocorusk
提出日時 2020-03-06 21:39:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 113,692 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-22 05:28:02
合計ジャッジ時間 2,388 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 38 ms
8,064 KB
testcase_12 AC 83 ms
10,936 KB
testcase_13 AC 70 ms
11,392 KB
testcase_14 AC 72 ms
11,504 KB
testcase_15 AC 74 ms
10,240 KB
testcase_16 AC 28 ms
6,912 KB
testcase_17 AC 39 ms
8,192 KB
testcase_18 AC 62 ms
10,368 KB
testcase_19 AC 59 ms
9,984 KB
testcase_20 AC 65 ms
10,624 KB
testcase_21 AC 74 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int f[2000020];
int main()
{
    int x; cin>>x;
    for(int i=1; i<=x; i++){
        for(int j=i; j<=x; j+=i) f[j]++;
    }
    for(int i=1; i<=x; i++) f[i]=i-f[i];
    vector<int> ans;
    int mn=1e9;
    for(int i=1; i<x; i++){
        if(abs(f[i]-f[x-i])<mn){
            mn=abs(f[i]-f[x-i]);
            ans.clear(); ans.push_back(i);
        }else if(abs(f[i]-f[x-i])==mn){
            ans.push_back(i);
        }
    }
    for(auto i:ans){
        cout<<i<<" "<<x-i<<endl;
    }
	return 0;
}
0