結果

問題 No.1409 Simple Math in yukicoder
ユーザー chocorusk
提出日時 2021-02-26 21:30:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,585 bytes
コンパイル時間 3,065 ms
コンパイル使用メモリ 182,168 KB
最終ジャッジ日時 2025-01-19 04:49:46
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
ll powmod(ll a, ll k, ll MOD){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
bool check(int r, int p){
    for(int d=2; d*d<=p-1; d++){
        if((p-1)%d!=0) continue;
        if(powmod(r, d, p)==1) return false;
        if(powmod(r, (p-1)/d, p)==1) return false;
    }
    return true;
}
int main()
{
    int t; cin>>t;
    while(t--){
        int v, x; cin>>v>>x;
        int p=v*x+1;
        if(p==2){
            cout<<1<<endl;
            continue;
        }
        int r=2;
        for(r=2; ; r++){
            if(check(r, p)){
                break;
            }
        }
        int ans[101];
        for(int i=0; i<x; i++){
            ans[i]=powmod(r, i*v, p);
        }
        sort(ans, ans+x);
        for(int i=0; i<x; i++){
            cout<<ans[i];
            if(i<x-1) cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}
0