結果

問題 No.1396 Giri
ユーザー moririn2528_cmoririn2528_c
提出日時 2021-02-14 21:32:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,350 ms / 2,000 ms
コード長 2,797 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 112,088 KB
実行使用メモリ 8,588 KB
最終ジャッジ日時 2023-09-29 14:42:25
合計ジャッジ時間 12,261 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1,286 ms
8,588 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1,296 ms
8,436 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 44 ms
4,380 KB
testcase_19 AC 535 ms
6,168 KB
testcase_20 AC 823 ms
7,032 KB
testcase_21 AC 1,137 ms
8,180 KB
testcase_22 AC 1,330 ms
8,528 KB
testcase_23 AC 1,301 ms
8,452 KB
testcase_24 AC 1,315 ms
8,560 KB
testcase_25 AC 1,350 ms
8,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=998244353;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

long long int pow_mod(long long int a,long long int n,long long int p=1e9+7){
    //a^n mod p
    long long int b=1,t=1;
    for(;b<=n;b<<=1);
    for(b>>=1;b>0;b>>=1){
        t*=t;
        if(t>=p)t%=p;
        if(n&b)t*=a;
        if(t>=p)t%=p;
    }
    return t;
}

long long int gcd(long long int a,long long int b){
    if(a<b)gcd(b,a);
    if(b==0)return a;
    return gcd(b,a%b);
}

long long int divide(long long int a,long long int b,long long int p=1e9+7){
    // a/b mod p
    // prime:p is prime
    if(a>=p)a%=p;
    if(a<0)a+=p;
    if(b>=p)b%=p;
    if(b<0)b+=p;
    a*=pow_mod(b,p-2,p);
    return a%p;
}

namespace sol{

    bool used[1100000];

    void solve(){
        int n,m;
        LL i,j,k;
        LL a,b,c;
        cin>>n;
        vector<int> pri;
        map<int,int> m1;
        for(i=2;i<=n;i++){
            if(used[i])continue;
            m1[i]=pri.size();
            pri.push_back(i);
            for(j=i*i;j<=n;j+=i){
                used[j]=true;
            }
        }
        vector<LL> cnt(pri.size(),0);

        for(i=2;i<=n;i++){
            a=i;
            for(j=0;pri[j]*pri[j]<=i;j++){
                for(k=0;a%pri[j]==0;k++,a/=pri[j]);
                if(k)cnt[j]=max(cnt[j],k);
            }
            if(a!=1){
                b=m1[a];
                cnt[b]=max(cnt[b],1LL);
            }
        }
        for(i=n;i>=2;i--){
            if(!used[i])break;
        }
        LL s=divide(1,i,MAX);
        for(i=0;i<pri.size();i++){
            for(j=0;j<cnt[i];j++){
                s*=pri[i];
                s%=MAX;
            }
        }
        cout<<s<<endl;
    }
}

int main(){
    sol::solve();
}
0