結果
問題 |
No.2479 Sum of Squares
|
ユーザー |
|
提出日時 | 2024-07-04 15:56:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 581 bytes |
コンパイル時間 | 742 ms |
コンパイル使用メモリ | 72,804 KB |
最終ジャッジ日時 | 2025-02-22 01:56:22 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <iostream> #include <vector> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); long long S, l, c, r; vector<long long> ans; cin >> S; while (S != 0) { for (l = 1, r = 1'000'000'001; l + 1 < r; ) { c = (l + r) / 2; if (c * c <= S) l = c; else r = c; } ans.push_back(l * l); S -= l * l; } cout << ans.size() << '\n' << ans[0]; for (int i = 1; i != ans.size(); ++i) cout << ' ' << ans[i]; cout << '\n'; return 0; }