結果

問題 No.3226 2×2行列累乗
ユーザー Sillpherth
提出日時 2025-08-25 09:46:06
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 663 bytes
コンパイル時間 704 ms
コンパイル使用メモリ 80,248 KB
実行使用メモリ 10,916 KB
最終ジャッジ日時 2025-08-25 09:46:11
合計ジャッジ時間 4,529 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 TLE * 1 -- * 1
other -- * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<iostream>

int main(void)
{
	int A,B,C,D,S,T,N,K,tS,n;
	std::cin >> A >> B >> C >> D >> S >> T >> N >> K;
	if(N=0)
	{
		std::cout << "1 1\n";
		return 0;
	}
	
	int SS = (S%K+K)%K;
	int ST = (T%K+K)%K;
	int cycle = 0;
	
	do
	{
		tS = S;
		S = ((A*tS+B*T)%K+K)%K;
		T = ((C*tS+D*T)%K+K)%K;
		//std::cout << S << " " << T << "\n";
		cycle++;
	}while((S != SS) || (T != ST));
	if(cycle = 1)
	{
		std::cout << SS << " " << ST <<"\n";
		return 0;
	}else
	{
		n = N%cycle;
		S = SS; T = ST;
		for(int i=0; i<n; i++)
		{
			tS = S;
			S = ((A*tS+B*T)%K+K)%K;
			T = ((C*tS+D*T)%K+K)%K;
		}
		std::cout << S << " " << T << "\n";
		return 0;
	}
}
0