結果
| 問題 |
No.613 Solitude by the window
|
| コンテスト | |
| ユーザー |
batasanblog
|
| 提出日時 | 2023-03-19 20:37:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,291 bytes |
| コンパイル時間 | 3,562 ms |
| コンパイル使用メモリ | 249,444 KB |
| 最終ジャッジ日時 | 2025-02-11 15:26:31 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#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);
batasanblog