社区讨论
蒟蒻请求巨佬帮助!
P3216[HNOI2011] 数学作业参与者 6已保存回复 12
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 12 条
- 当前快照
- 1 份
- 快照标识符
- @mi7ysd96
- 此快照首次捕获于
- 2025/11/21 05:49 4 个月前
- 此快照最后确认于
- 2025/11/21 06:45 4 个月前
结果一直是0 , 查不出原因!
CPP#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
struct martix
{
ll f[4][4];
}ans , e;
ll n , m;
martix operator * (const martix & a,const martix & b)
{
martix res;
memset(res.f,0,sizeof res.f);
for(int k = 1;k <= 3;k ++) for(int i = 1;i <= 3;i ++) for(int j = 1;j <= 3;j ++)
res.f[i][j] = (res.f[i][j] + res.f[i][k] * res.f[k][j] % m) % m;
return res;
}
void ksm(martix a,ll b)
{
martix res;
memset(res.f,0,sizeof res.f);
for(int i = 1;i <= 3;i ++) res.f[i][i] = 1;
while(b)
{
if(b & 1) res = a * res;
a = a * a;
b >>= 1;
}
ans = res * ans;
}
ll fuc()
{
ans.f[1][3] = 1;
e.f[1][2] = 1;
e.f[1][3] = 1;
e.f[2][2] = 1;
e.f[2][3] = 1;
e.f[3][3] = 1;
for(ll tmp = 1;tmp <= n;tmp *= 10)
{
e.f[1][1] = tmp * 10;
ksm(e,min(tmp*9,n - tmp + 1));
}
return ans.f[1][1] % m;
}
int main()
{
scanf("%lld%lld",&n,&m);
printf("%lld",fuc() % m);
return 0;
}
回复
共 12 条回复,欢迎继续交流。
正在加载回复...