結果

問題 No.2189 六平方和
ユーザー SSRSSSRS
提出日時 2023-01-13 22:03:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,021 bytes
コンパイル時間 1,346 ms
コンパイル使用メモリ 167,176 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 03:48:44
合計ジャッジ時間 4,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b, long long m){
  long long ans = 1;
  while (b > 0){
    if (b % 2 == 1){
      ans *= a;
      ans %= m;
    }
    a *= a;
    a %= m;
    b /= 2;
  }
  return ans;
}
int main(){
  long long N;
  int M, B;
  cin >> N >> M >> B;
  long long x = modpow(M, N / 2, B);
  if (x == 0){
    x = B;
  }
  if (N % 2 == 0){
    assert(x * x % B == modpow(M, N, B));
    cout << "YES" << endl;
    cout << x << ' ' << B << ' ' << B << ' ' << B << ' ' << B << ' ' << B << endl;
  } else {
    vector<int> C(6, 0);
    for (int i = 0; i < 6; i++){
      for (int j = M; j >= 0; j--){
        if (j * j <= M){
          C[i] = j * j;
          M -= j * j;
          break;
        }
      }
    }
    cout << "YES" << endl;
    for (int i = 0; i < 6; i++){
      long long ans = (long long) C[i] * x % B;
      if (ans == 0){
        ans = B;
      }
      cout << ans;
      if (i < 5){
        cout << ' ';
      }
    }
    cout << endl;
  }
}
0