結果

問題 No.950 行列累乗
ユーザー chocoruskchocorusk
提出日時 2019-11-26 01:36:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,020 bytes
コンパイル時間 1,314 ms
コンパイル使用メモリ 109,964 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-11-08 10:55:40
合計ジャッジ時間 7,387 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other TLE * 1 -- * 56
権限があれば一括ダウンロードができます

ソースコード

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>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
ll p;
using arr=array<ll, 2>;
using Mat=array<arr, 2>;
Mat matmul(Mat a, Mat b){
	Mat c={};
	for(int i=0; i<2; i++){
		for(int j=0; j<2; j++){
			for(int k=0; k<2; k++){
				(c[i][j]+=a[i][k]*b[k][j])%=p;
			}
		}
	}
	return c;
}
int main()
{
    cin>>p;
	Mat a, b;
	cin>>a[0][0]>>a[0][1]>>a[1][0]>>a[1][1]>>b[0][0]>>b[0][1]>>b[1][0]>>b[1][1];
	Mat ap=a;
	for(int i=1; i<p*p; i++){
		if(ap==b){
			cout<<i<<endl;
			return 0;
		}
		ap=matmul(ap, a);
	}
	cout<<-1<<endl;
	return 0;
}
0