結果

問題 No.613 Solitude by the window
ユーザー batasanblogbatasanblog
提出日時 2023-03-19 20:37:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 4,374 ms
コンパイル使用メモリ 262,660 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 17:53:37
合計ジャッジ時間 5,322 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
//using mint = static_modint<998244353>;
//using mint = modint;
using mint = static_modint<1000000007>;
using vm = vector<mint>;
using vvm = vector<vm>;
ostream &operator<<(ostream &o,const mint &m){cout<<m.val();return o;}
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
#define reps(i,s,n) for(ll i=(s);i<(ll)(n);++i)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);++i)
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const long long INF = 1e18;

#ifdef DEBUG
#include <debug.hpp>
#endif

ll powmod(ll x,ll e,ll m){
	ll po=1LL;
	for(ll i=63LL;i>=0;--i){
		po=po*po%m;
		if(e&(1LL<<i))po=(po*x)%m;
	}
	return po;
}
int main(){
#ifdef DEBUG
	cout << "--- Input ---" << endl;
#endif
	ll n,m;
	cin >> n>>m;

#ifdef DEBUG
	cout << "--- Logic ---" << endl;
#endif
	ll p;
	if(m==2||m%12==1||m%12==11)p=m-1;
	else p=m+1;
	ll e=powmod(2,n,p);
	ll x=1,y=0;
	for(ll i=31;i>=0;--i){
		ll z=(x*x+3*y*y)%m, w=2*x*y%m;
		x=z,y=w;
		if(e&(1LL<<i)){
			z=(2*x+3*y)%m; w=(x+2*y)%m;
			x=z;y=w;
		}
	}

#ifdef DEBUG
	cout << "--- Answer ---" << endl;
#endif
	cout<<(2*x+m-2)%m<<endl;
}
//cout << fixed << setprecision(9);
0