作为一个不是很会用矩阵的人QAQQQQQQQQ,我们考虑下构造一下下等比数列,然后用推出来的通项公式解决.......数学渣算了好几次QAQQQQ
然而UOJ的hack并没有通过QAQQQQQQQ,并没能发现为什么
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #define LL long long #define fo(i,a,b) for(int i=a;i<=b;i++) using namespace std; LL read() { LL d=0,f=1;char s=getchar(); while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();} while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();} return d*f; } #define N 1000010 #define inf 1000000007 LL a,b,c,d,n,m; LL n1,m1; void give(char *s,LL &k,LL mod) { int len=strlen(s); fo(i,0,len-1) k=(k*10+s[i]-'0')%mod; } LL f(LL a,LL b) { if(b==1)return a; if(b==0)return 1; if(b==2)return a*a%inf; LL t=f(a,b/2);t=t*t;t%=inf; if(b%2)return (t*a)%inf; else return t; } LL ny(LL a) { return f(a,inf-2); } int main() { char ch1[N],ch2[N]; scanf("%s%s",ch1,ch2); a=read(),b=read(),c=read(),d=read(); give(ch1,n,inf-1);give(ch2,m,inf-1); give(ch1,n1,inf);give(ch2,m1,inf); int flag=1; if(a!=1&&c==1&&d==1)flag=0; if(a==1) { b=(b*(m1-1)%inf*c+d)%inf; a=c; }else { LL t=b*ny(a-1)%inf; LL an=f(a,m-1); b=(t*(an-1)%inf*c+d)%inf; a=(an*c)%inf; } // cout<<a<<' '<<b<<endl; LL ans=0; if(a==1)ans=(1+n1*b)%inf; else { LL t=b*ny(a-1)%inf; LL an=f(a,n); ans=((an-1)*t%inf+an)%inf; } ans-=d; ans*=ny(c); ans%=inf; ans+=inf; ans%=inf; cout<<ans<<endl; return 0; }