結果

問題 No.1006 Share an Integer
ユーザー tnakao0123tnakao0123
提出日時 2020-03-07 00:48:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,160 bytes
コンパイル時間 935 ms
コンパイル使用メモリ 93,496 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-22 11:36:36
合計ジャッジ時間 7,078 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1006.cc:  No.1006 Share an Integer - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_X = 2000000;

/* typedef */

/* global variables */

int as[MAX_X];

/* subroutines */

inline int f(int n) {
  int c = 0;
  for (int p = 1; p * p <= n; p++)
    if (n % p == 0)
      c += (p * p < n) ? 2 : 1;
  return n - c;
}

/* main */

int main() {
  int x;
  scanf("%d", &x);

  int mind = x, m = 0;
  for (int a = 1; a * 2 <= x; a++) {
    int b = x - a;
    int d = abs(f(b) - f(a));
    //printf("a=%d, b=%d -> d=%d\n", a, b, d);

    if (mind > d) {
      mind = d;
      m = 0;
      as[m++] = a;
      if (b != a) as[m++] = b;
    }
    else if (mind == d) {
      as[m++] = a;
      if (b != a) as[m++] = b;
    }
  }
  
  for (int i = 0; i < m; i++) printf("%d %d\n", as[i], x - as[i]);
  return 0;
}
0