結果

問題 No.1006 Share an Integer
ユーザー eSeFeSeF
提出日時 2020-02-18 17:56:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 195,580 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 23:55:04
合計ジャッジ時間 3,871 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 61 ms
5,376 KB
testcase_12 AC 101 ms
5,376 KB
testcase_13 AC 106 ms
5,376 KB
testcase_14 AC 107 ms
5,376 KB
testcase_15 AC 92 ms
5,376 KB
testcase_16 AC 46 ms
5,376 KB
testcase_17 AC 62 ms
5,376 KB
testcase_18 AC 93 ms
5,376 KB
testcase_19 AC 89 ms
5,376 KB
testcase_20 AC 96 ms
5,376 KB
testcase_21 AC 106 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int f(int N){
    int d=0;
    for(int i=2;i<=sqrt(N);i++){
        if(N%i==0){
            if(N/i==i)d++;
            else d+=2;
        }
    }
    return N-d;
}
int main()
{
    int X;
    cin >> X;
    int mid = X/2;
    int width=2*((int)sqrt(X)+1);
    int mindif=X;
    for(int A=max(1,mid-width);A-(X-A)<2*width;A++){
        mindif=min(mindif,abs(f(A)-f(X-A)));
    }
    for(int A=max(1,mid-width);A-(X-A)<2*width;A++){
       if(abs(f(A)-f(X-A))==mindif){
           cout << A << " " << X-A << endl;
       }
    }
    return 0;
}
0