結果

問題 No.2785 四乗足す四の末尾の0
ユーザー rgnerdplayer
提出日時 2025-05-01 15:30:39
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,052 bytes
コンパイル時間 3,779 ms
コンパイル使用メモリ 275,068 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-01 15:30:45
合計ジャッジ時間 5,581 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    auto solve = [&]() {
        i64 n;
        cin >> n;

        n = abs(n);

        // (n^2 + 2n + 2) (n^2 - 2n + 2)

        if (n == 1) {
            cout << "Yes" << '\n';
        } else {
            cout << "No" << '\n';
        }

        auto get = [&](i64 n) {
            array<int, 3> res{};
            while (n % 10 == 0) {
                n /= 10;
                res[0]++;
            }
            while (n % 2 == 0) {
                n /= 2;
                res[1]++;
            }
            while (n % 5 == 0) {
                n /= 5;
                res[2]++;
            }
            return res;
        };

        auto [x10, x2, x5] = get(n * n + 2 * n + 2);
        auto [y10, y2, y5] = get(n * n - 2 * n + 2);

        int ans = x10 + y10 + min(x2 + y2, x5 + y5);

        cout << ans << '\n';
    };

    int t;
    cin >> t;

    while (t--) {
        solve();
    }
    
    return 0;
}
0