結果

問題 No.1006 Share an Integer
ユーザー tnakao0123
提出日時 2020-03-07 00:50:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,178 bytes
コンパイル時間 979 ms
コンパイル使用メモリ 97,548 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-10-14 10:56:20
合計ジャッジ時間 4,624 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 TLE * 2 -- * 9
権限があれば一括ダウンロードができます

ソースコード

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;
    }
  }
  sort(as, as + m);

  for (int i = 0; i < m; i++) printf("%d %d\n", as[i], x - as[i]);
  return 0;
}
0