社区讨论
萌新求助,我是妹子qwq
P4838P哥破解密码参与者 26已保存回复 36
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 36 条
- 当前快照
- 1 份
- 快照标识符
- @mi6zdxv6
- 此快照首次捕获于
- 2025/11/20 13:18 4 个月前
- 此快照最后确认于
- 2025/11/20 17:15 4 个月前
emmm标题心虚
不过这个题...我过了....有毒简直
过了以后发现,自己可能打错了...
矩乘那个地方..
CPPMatrix operator *(Matrix const & b)const{
Matrix ret;ret.clear();
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
ret.a[i][k]=(ret.a[i][k]+1ll*a[i][j]*b.a[j][k])%mod;
}
}
}
return ret;
}
怎么过的呢????求问...为什么没出锅
马上NOIP了求各位dalao帮帮我
这是代码emmmm谢谢谢谢
CPP#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define M(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long ll;
const int mod=19260817;
ll n,m;
struct Matrix{
ll a[3][3];
void clear(){
M(a);
}
Matrix operator *(Matrix const & b)const{
Matrix ret;ret.clear();
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
ret.a[i][k]=(ret.a[i][k]+1ll*a[i][j]*b.a[j][k])%mod;
}
}
}
return ret;
}
}A,B;
Matrix qpow(Matrix A,int d){
Matrix res;
res.a[0][0]=1;res.a[0][1]=0;res.a[0][2]=0;
res.a[1][0]=0;res.a[1][1]=1;res.a[1][2]=0;
res.a[2][0]=0;res.a[2][1]=0;res.a[2][2]=1;
for(;d;d>>=1,A=A*A)if(d&1)res=res*A;
return res;
}
int main(){
// freopen("fence.in","r",stdin);
scanf("%d",&m);
A.a[0][0]=1;A.a[0][1]=1;A.a[0][2]=1;
A.a[1][0]=1;A.a[1][1]=0;A.a[1][2]=0;
A.a[2][0]=0;A.a[2][1]=1;A.a[2][2]=0;
B.a[0][0]=7;B.a[1][0]=4;B.a[2][0]=2;
while(m--){
scanf("%d",&n);
if(n==1){
cout<<2<<endl;continue;
}
if(n==2){
cout<<4<<endl;continue;
}
if(n==3){
cout<<7<<endl;continue;
}
Matrix C=qpow(A,n-3)*B;
printf("%lld\n",C.a[0][0]);
}
}
回复
共 36 条回复,欢迎继续交流。
正在加载回复...