QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#823119 | #8428. Partition into Teams | cdx123456 | WA | 0ms | 3648kb | C++14 | 480b | 2024-12-20 19:30:36 | 2024-12-20 19:30:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,mod,a[100010],f[100010];
int q_pow(int x,int y){
if(!y) return 1;
int z=q_pow(x,y>>1);
if(y&1) return z*z%mod*x%mod;
else return z*z%mod;
}
signed main(){
cin>>n>>mod;
a[0]=f[1]=f[2]=1;
for(int i=3;i<=n;i++) f[i]=f[i-1]+f[i-2],f[i]%=mod;
for(int i=1;i<n;i++) a[i]=3*a[i-1]%mod-f[i-1]*(f[i-1]+1)%mod+mod,a[i]%=mod;
cout<<(q_pow(3,n)-a[n-1]+mod)%mod*q_pow(2,mod-2)%mod;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
5 5
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 7
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3536kb
input:
789 97
output:
61
result:
wrong answer 1st numbers differ - expected: '53', found: '61'