結果

問題 No.634 硬貨の枚数1
ユーザー とばり
提出日時 2018-09-07 18:13:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 168,504 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 04:08:11
合計ジャッジ時間 4,115 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 75
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using int64 = long long;
using uint64 = unsigned long long;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> triangularNumbers;
    for (int n = 1, tri = 1; tri <= N; n++, tri = n * (n + 1) / 2)
    {
        if (tri == N)
        {
            cout << 1 << endl;
            return 0;
        }
        triangularNumbers.push_back(tri);
    }

    int m = triangularNumbers.size();
    for (int i = 0; i < m; i++)
    {
        for (int j = i; j < m; j++)
        {
            int sum = triangularNumbers[i] + triangularNumbers[j];

            if (sum == N)
            {
                cout << 2 << endl;
                return 0;
            }
        }
    }
    cout << 3 << endl;

    return 0;
}
0