結果
問題 | No.2479 Sum of Squares |
ユーザー |
![]() |
提出日時 | 2024-01-09 17:38:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 763 bytes |
コンパイル時間 | 1,050 ms |
コンパイル使用メモリ | 86,192 KB |
最終ジャッジ日時 | 2025-02-18 16:49:01 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <iostream>#include <cassert>#include <cmath>#include <vector>using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);long long S; cin >> S;vector<long long> ans = { S };auto is_square = [](long long x) -> bool {long long y = (long long)sqrtl((long double)x);return y * y == x;};while (!is_square(ans.back())) {long long x = (long long)sqrtl((long double)ans.back());long long nxt = ans.back() - x * x;ans.back() = x * x;ans.push_back(nxt);}assert(ans.size() <= 15);long long s = 0;cout << ans.size() << endl;for (int i = 0; i < ans.size(); i++) {s += ans[i];cout << ans[i] << (i + 1 == ans.size()? "\n": " ");}assert(s == S);return 0;}