結果

問題 No.2358 xy+yz+zx=N
ユーザー tnakao0123tnakao0123
提出日時 2023-06-30 18:35:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 842 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 62,104 KB
実行使用メモリ 6,596 KB
最終ジャッジ日時 2023-09-21 12:09:42
合計ジャッジ時間 2,659 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 36 ms
6,400 KB
testcase_09 AC 37 ms
6,596 KB
testcase_10 AC 23 ms
4,384 KB
testcase_11 AC 25 ms
4,744 KB
testcase_12 AC 16 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2358.cc:  No.2358 xy+yz+zx=N - yukicoder
 */

#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>
 
using namespace std;

/* constant */

/* typedef */

typedef vector<int> vi;
typedef set<vi> svi;

/* global variables */

/* subroutines */

/* main */

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

  svi as;
  for (int x = 0; x * x * 3 <= n; x++) {
    int m = n + x * x;
    for (int p = max(1, x); p * p <= m; p++)
      if (m % p == 0) {
	int q = m / p;
	int y = p - x, z  = q - x;
	if (x <= y && y <= z) {
	  as.insert({x, y, z});
	  as.insert({x, z, y});
	  as.insert({y, x, z});
	  as.insert({y, z, x});
	  as.insert({z, x, y});
	  as.insert({z, y, x});
	}
      }
  }

  printf("%d\n", (int)as.size());
  for (auto &v: as)
    printf("%d %d %d\n", v[0], v[1], v[2]);

  return 0;
}
0