結果

問題 No.2479 Sum of Squares
ユーザー mkreemmkreem
提出日時 2024-01-29 07:08:06
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,133 ms / 2,000 ms
コード長 2,295 bytes
コンパイル時間 3,046 ms
コンパイル使用メモリ 248,988 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-29 07:08:29
合計ジャッジ時間 11,668 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1,133 ms
6,676 KB
testcase_04 AC 366 ms
6,676 KB
testcase_05 AC 209 ms
6,676 KB
testcase_06 AC 253 ms
6,676 KB
testcase_07 AC 243 ms
6,676 KB
testcase_08 AC 313 ms
6,676 KB
testcase_09 AC 268 ms
6,676 KB
testcase_10 AC 296 ms
6,676 KB
testcase_11 AC 269 ms
6,676 KB
testcase_12 AC 302 ms
6,676 KB
testcase_13 AC 198 ms
6,676 KB
testcase_14 AC 255 ms
6,676 KB
testcase_15 AC 253 ms
6,676 KB
testcase_16 AC 276 ms
6,676 KB
testcase_17 AC 268 ms
6,676 KB
testcase_18 AC 254 ms
6,676 KB
testcase_19 AC 284 ms
6,676 KB
testcase_20 AC 280 ms
6,676 KB
testcase_21 AC 237 ms
6,676 KB
testcase_22 AC 266 ms
6,676 KB
testcase_23 AC 230 ms
6,676 KB
testcase_24 AC 260 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef INCLUDED_main
#define INCLUDED_main

#include __FILE__

const ll mod = 998244353; using mint = atcoder::modint998244353;
//const ll mod = 1000000007; using mint = atcoder::modint1000000007;

// @brief 繰り返し二乗法を利用した、x^nの求値
ll power(ll x, ll n){
  ll res = 1;

  while(n){
    if(n & 1) res *= x; // nの2進数表記の下からi(0-indexed)桁目が1なら、x^(2^i)を掛けていく
    x *= x;
    n >>= 1; // (n = n>>1 nの各ビットを右へシフト)
  }
  
  return res;
}




int main(){

  ll s; cin >> s;

  ll M = 1;
  while(s >= (M+1)*(M+1)) M++;
  vector<ll> ans;
  while(s >= 1){
    while(s < M*M){
      M--;
    }
    s -= M*M;
    ans.push_back(M*M);
  }

  cout << ans.size() << endl;
  fore(x, ans) cout << x << ' ';

}

#else 

#include <bits/stdc++.h>
#include <atcoder/modint>

using ll = long long;
using ld = long double;
using Graph = std::vector<std::vector<int>>;
#define endl '\n'
#define INF 1000000039
#define LLINF 393939393939393939
#define fore(i, a) for(auto &i : a)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define erep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define part(x, a, b) x.begin()+a, x.begin()+b+1
#define rpart(x, a, b) x.rbegin()+a, x.rbegin()+b+1
#define pcnt(x) __builtin_popcount(x)
#define llpcnt(x) __builtin_popcountll(x)
template<typename T>
using pq = std::priority_queue<T>;
template<typename T>
using pqg = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
bool chmax(T &a, const T &b){
  if(a < b){ a = b; return 1; }
  else return 0;
}
template<typename T>
bool chmin(T &a, const T &b){
  if(a > b){ a = b; return 1; }
  else return 0;
}
// 多次元配列の生成
template<size_t Dimention, typename T>
class Mvector : public std::vector<Mvector<Dimention-1, T>>{
public:
  template<typename N, typename... Sizes>
  Mvector(T init, N n, Sizes... sizes) : std::vector<Mvector<Dimention-1, T> >(n, Mvector<Dimention-1, T>(init, sizes...))
  { }
};
template<typename T>
class Mvector<1, T> : public std::vector<T>{
public:
  template<typename N>
  Mvector(T init, N n) : std::vector<T>(n, init)
  { }
};


using namespace std;

#endif
0