社区讨论
矩阵快速幂一直输出0求调
AT_abc129_f [ABC129F] Takahashi's Basics in Education and Learning参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lok2xsoj
- 此快照首次捕获于
- 2023/11/04 21:28 2 年前
- 此快照最后确认于
- 2023/11/04 23:14 2 年前
RT
CPP#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
#include<bitset>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
#define endl '\n'
using namespace std;
ll A,B,L,mod;
struct node
{
ll n,m,a[4][4];
node operator *(const node &b)const
{
node ans;
ans.n=n,ans.m=b.m;
for(int i=1;i<=ans.n;++i)
{
for(int j=1;j<=ans.m;++j)
{
ans.a[i][j]=0;
for(int k=1;k<=b.m;++k)
{
ans.a[i][j]=(ans.a[i][j]+(a[i][k]%mod)*(b.a[k][j]%mod))%mod;
}
}
}
return ans;
}
}sum;
node fastpow(node a,ll b)
{
node res=a;--b;
while(b)
{
if(b&1) res=res*a;
a=a*a;
b>>=1;
}
return res;
}
inline ll read()
{
ll x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
inline void write(int x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9) write(x/10);
putchar(x%10+'0');
return;
}
int main()
{
L=read(),A=read(),B=read(),mod=read();
sum.n=3,sum.m=1,sum.a[1][1]=0,sum.a[2][1]=A%mod,sum.a[3][1]=1;
ll maxn=1;
for(int i=1;i<=18;++i)
{
maxn*=10;
if(A<maxn)
{
ll tmp=(maxn-A-1)/B+1;
if(tmp>L) tmp=L;
L-=tmp;
if(tmp)
{
A+=tmp*B;
node num;num.n=num.m=3;
num.a[1][1]=maxn%mod,num.a[1][2]=1,num.a[1][3]=0;
num.a[2][1]=0,num.a[2][2]=1,num.a[2][3]=B%mod;
num.a[3][1]=0,num.a[3][2]=0,num.a[3][3]=1;
sum=fastpow(num,tmp)*sum;
}
}
}
cout<<sum.a[1][1]<<endl;
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...