結果

問題 No.2444 一次変換と体積
ユーザー momoyuumomoyuu
提出日時 2023-08-25 23:07:58
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,385 bytes
コンパイル時間 2,768 ms
コンパイル使用メモリ 248,572 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-25 23:08:02
合計ジャッジ時間 3,785 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 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 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll mod;
//const ll mod = 998'244'353;
//const ll mod = 1'000'000'007;
//const ll mod = 67'280'421'310'721;
struct mint{
    long long x;
    mint(long long x=0):x((x%mod+mod)%mod){}
    mint operator-() const{
        return mint(-x);
    }
    mint& operator+=(const mint& a){
        if((x+=a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator-=(const mint& a){
        if((x+=mod-a.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator*=(const  mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    mint pow(long long n) const {
        assert(0 <= n);
        mint a = *this, r = 1;
        while (n) {
            if (n & 1) r *= a;
            a *= a;
            n >>= 1;
        }
        return r;
    }
    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint& a){
        return (*this)*=a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    bool operator==(const mint& a) const {
        return x == a.x;
    }
    bool operator<(const mint& a) const{
        return x < a.x;
    }
};

template< typename T >
vector<vector<T>> mattimes(vector<vector<T>> &A,vector<vector<T>> &B){
    assert(A.size()==B.size());
    int n = A.size();
    vector<vector<T>> res(n,vector<T>(n,0));
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)for(int k=0;k<n;k++)res[i][j]+=A[i][k]*B[k][j];
    return res;
}

template< typename T >
vector<T> mattimes(vector<vector<T>> &A,vector<T> &B){
    assert(A.size()==B.size());
    int n = A.size();
    vector<T> res(n,0);
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)res[i]+=A[i][j]*B[j];
    return res;
}

template< typename T >
vector<vector<T>> matpow(vector<vector<T>> a,ll k){
    int n = a.size();
    vector<vector<T>> res(n,vector<T>(n,0));
    for(int i=0;i<n;i++)res[i][i] = T(1);
    for(;k;k>>=1){
        if(k&1) res = mattimes<T>(res,a);
        a = mattimes<T>(a,a);
    }
    return res;
}

ll gcd(ll a,ll b){
    if(b) return gcd(b,a%b);
    return a;
}
int64_t euler_phi(int64_t n) {
  int64_t ret = n;
  for(int64_t i = 2; i * i <= n; i++) {
    if(n % i == 0) {
      ret -= ret / i;
      while(n % i == 0) n /= i;
    }
  }
  if(n > 1) ret -= ret / n;
  return ret;
}

int main(){
    int n;
    cin>>n>>mod;
    vector<vector<mint>> a(3,vector<mint>(3,0));
    for(int i = 0;i<3;i++){
        for(int j = 0;j<3;j++){
            ll b;
            cin>>b;
            a[i][j] = b;
        }
    }
    mint now = a[0][0] * a[1][1] * a[2][2] + a[0][1] * a[1][2] * a[2][0] + a[0][2] * a[1][0] * a[2][1];
    now -= a[0][2] * a[1][1] * a[2][0] + a[0][1] * a[1][0] * a[2][2] + a[0][0]*a[1][2]*a[2][1];
    now = now.pow(n);
    ll x = now.x;
    if(x==0||gcd(mod,x)!=1){
        if(x==0) cout<<0<<endl;
        else cout<<"infty"<<endl;
    }else{
        ll want = euler_phi(mod);
        now = now.pow(want-1);
        cout<<now<<endl;
    }


}
0