emm卡常

我本来写成了这个样子:

 #include<bits/stdc++.h>
using namespace std; typedef long long LL;
const LL mod = 1e9+;
struct node{
LL s[][];
};
LL m0[][]={,,,};
LL m1[][]={-,,,-}; node mult(node x,node y)
{
node ans;
memset(ans.s,,sizeof(ans.s));
for(int i=;i<;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
ans.s[i][j]=(ans.s[i][j]+(x.s[i][k]*y.s[k][j])%mod)%mod;
return ans;
} node quickpow(node t,LL x)
{
node ans,now=t;
memset(ans.s,,sizeof(ans.s));
ans.s[][]=ans.s[][]=;
while(x)
{
if(x&) ans=mult(ans,now);
now=mult(now,now);x/=;
}
return ans;
} int main()
{
//freopen("a.in","r",stdin);
//freopen("b.out","w",stdout);
int T;LL a,b;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&a,&b);
m0[][]=a;m1[][]=a;
node t0,t1;
for(int i=;i<;i++)
for(int j=;j<;j++)
{
t0.s[i][j]=m0[i][j];
t1.s[i][j]=m1[i][j];
}
t0=quickpow(t0,*b-);
t1=quickpow(t1,*b-);
LL ans=;
ans=(((t0.s[][]+t0.s[][])%mod+(-t1.s[][]+t1.s[][])%mod)/)%mod;
printf("%lld\n",ans);
}
return ;
}

后来把矩乘全部直接改掉才a了

 #include<bits/stdc++.h>
using namespace std; typedef long long LL;
const LL mod = 1e9+;
LL a,b,ans[][],now[][],p[][]; void quickpow(int tmp,LL x)
{
if(!tmp)
{
now[][]=,now[][]=;
now[][]=a,now[][]=;
}
else
{
now[][]=-,now[][]=;
now[][]=a,now[][]=-;
}
ans[][]=,ans[][]=;
ans[][]=,ans[][]=;
while(x)
{
if(x&)
{
for(int i=;i<;i++)
for(int j=;j<;j++)
p[i][j]=ans[i][j];
ans[][]=(p[][]*now[][]+p[][]*now[][])%mod;
ans[][]=(p[][]*now[][]+p[][]*now[][])%mod;
ans[][]=(p[][]*now[][]+p[][]*now[][])%mod;
ans[][]=(p[][]*now[][]+p[][]*now[][])%mod;
}
for(int i=;i<;i++)
for(int j=;j<;j++)
p[i][j]=now[i][j];
now[][]=(p[][]*p[][]+p[][]*p[][])%mod;
now[][]=(p[][]*p[][]+p[][]*p[][])%mod;
now[][]=(p[][]*p[][]+p[][]*p[][])%mod;
now[][]=(p[][]*p[][]+p[][]*p[][])%mod;
x/=;
}
} int main()
{
//freopen("a.in","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&a,&b);
quickpow(,*b-);
LL sum=(ans[][]+ans[][])%mod;
quickpow(,*b-);
sum=((sum+(-ans[][]+ans[][])%mod)/)%mod;
printf("%lld\n",sum);
}
return ;
}

【acmm】一道简单的数学题的更多相关文章

  1. loj#6229 这是一道简单的数学题

    \(\color{#0066ff}{ 题目描述 }\) 这是一道非常简单的数学题. 最近 LzyRapxLzyRapx 正在看 mathematics for computer science 这本书 ...

  2. loj#6229. 这是一道简单的数学题 (??反演+杜教筛)

    题目链接 题意:给定\(n\le 10^9\),求:\(F(n)=\sum_{i=1}^n\sum_{j=1}^i\frac{\mathrm{lcm}(i,j)}{\mathrm{gcd}(i,j)} ...

  3. LOJ#6229. 这是一道简单的数学题(莫比乌斯反演+杜教筛)

    题目链接 \(Description\) 求\[\sum_{i=1}^n\sum_{j=1}^i\frac{lcm(i,j)}{gcd(i,j)}\] 答案对\(10^9+7\)取模. \(n< ...

  4. loj6229 这是一道简单的数学题

    https://loj.ac/problem/6229 题解:https://blog.csdn.net/Vectorxj/article/details/79094659 套路推式子,杜教筛,证明复 ...

  5. 【学术篇】luogu3768 简单的数学题(纯口胡无代码)

    真是一道"简单"的数学题呢~ 反演题, 化式子. \[ ans=\sum_{i=1}^n\sum_{j=1}^nijgcd(i,j) \\ =\sum_{i=1}^n\sum_{j ...

  6. NYOJ 330 一个简单的数学题【数学题】

    /* 题目大意:求解1/n; 解题思路:写一个输出小数的算法 关键点:怎样处理小数点循环输出 解题人:lingnichong 解题时间:2014-10-18 09:04:22 解题体会:输出小数的算法 ...

  7. 又一道简单题&&Ladygod(两道思维水题)

    Ladygod Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit S ...

  8. 【数学】HPU--1037 一个简单的数学题

    1037: 一个简单的数学题 [数学] 时间限制: 1 Sec 内存限制: 128 MB提交: 259 解决: 41 统计 题目描述 小明想要知道$a^b$的值,但是这个值会非常的大. 所以退而求其次 ...

  9. 【Luogu3768】简单的数学题(莫比乌斯反演,杜教筛)

    [Luogu3768]简单的数学题(莫比乌斯反演,杜教筛) 题面 洛谷 \[求\sum_{i=1}^n\sum_{j=1}^nijgcd(i,j)\] $ n<=10^9$ 题解 很明显的把\( ...

随机推荐

  1. linux虚拟机发邮件给163邮件

    配置/etc/mail.rc文件 set from=xxxxxxxx@163.com smtp=smtp.163.com set smtp-auth-user=yinhuanyi_cn@163.com ...

  2. Communications link failure--分析之(JDBC的多种超时情况)

    本文是针对特定的情景下的特定错误,不是所有Communications link failure错误都是这个引起的,重要的区分特点是:程序是不是在卡主后两个小时(服务器的设置)后程序才感知到,才抛出了 ...

  3. nodejs 调试

    什么语言入门的准备功能就是写helloworld, 调试. 用惯了chrome的话,推荐用chrome自带的调试器来调试.很方便. 在地址栏中输入 chrome://inspect 并按回车,会打开如 ...

  4. linux & zip & tar

    linux & zip & tar https://zzk.cnblogs.com/s?w=blog%3Axgqfrms%20zip # zip -r 递归 file_name.zip ...

  5. Monkey自动化测试

    Monkey简介 语法参数 实际应用 一.Monkey简介 1.什么是Monkey? 基于健壮性.稳定性的考虑:如果将一个应用交给一个人长时间不停地乱点乱按,程序会怎么样? 有时候运行相同系列的测试, ...

  6. 第93天:CSS3 中边框详解

    CSS3 边框详解 其中边框圆角.边框阴影属性,应用十分广泛,兼容性也相对较好,具有符合渐进增强原则的特征,我们需要重点掌握. 一.边框圆角  border-radius    每个角可以设置两个值 ...

  7. CF486D-Valid Sets

    题目 给出一个\(n\)个点的树,每个点有权值\(a_i\),再给出一个\(d\),问有多少个非空点集满足: 点集在树上构成联通子图 \[\max _{v\in S}a_v -\min _{v\in ...

  8. SQL 临时表或表变量替代游标(转)

    1.如果表没有自动增长的标识列(int) 使用临时表 SELECT IDENTITY(int) NewID ,.. INTO #tmp FROM YouTable 2.表有标识列 使用表变量 INSE ...

  9. 【刷题】洛谷 P3807 【模板】卢卡斯定理

    题目背景 这是一道模板题. 题目描述 给定\(n,m,p( 1\le n,m,p\le 10^5)\) 求 \(C_{n+m}^{m}\ mod\ p\) 保证 \(p\) 为prime \(C\) ...

  10. [TJOI2008]彩灯 线性基

    题面 题面 题解 题意:给定n个01串,求互相异或能凑出多少不同的01串. 线性基的基础应用. 对于线性基中的01串,如果我们取其中一些凑成一个新的01串,有一个重要的性质:任意2个不同方案凑出的01 ...