結果

問題 No.2189 六平方和
ユーザー lddlinanlddlinan
提出日時 2023-03-16 00:58:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,200 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 102,052 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 12:40:06
合計ジャッジ時間 2,070 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;



int expit(LL b, LL e, int m) {
    LL r=1;
    while(e) {
        if (e&1) { r*=b; r%=m; }
        b*=b; b%=m;
        e>>=1;
    }
    return r;
}
int main() {
    int i, m, b,v , f, k;
    int ff[8];
    LL n, vv; 
    scanf("%lld %d %d", &n, &m, &b);
    v=expit(m, n/2, b);
    printf("YES\n");
    if (n&1) {
        // decompose m to six
        for (k=0; k<6; k++) {
            ff[k]=0;
            if (m) {
                f=sqrt(m);
                if (f*f>m) f--;
                ff[k]=f;
                m-=f*f;
            }
        }
        for (k=0; k<6; k++) {
            vv=v; vv*=ff[k]; vv%=b; if (vv==0) vv=b; 
            if (k==5) printf("%d\n", vv);
            else printf("%d ", vv);
        }
    } else {
        if (v==0) v=b;
        printf("%d %d %d %d %d %d\n", v, b, b, b, b, b);
    }
    return 0;
}
0