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. lintcode-464-整数排序 II

    464-整数排序 II 给一组整数,按照升序排序.使用归并排序,快速排序,堆排序或者任何其他 O(n log n) 的排序算法. 样例 给出 [3, 2, 1, 4, 5], 排序后的结果为 [1, ...

  2. week1读构建之法-读书笔记

    最开始听见杨老师说邹欣老师这个名字总觉得很熟悉,后来看见博客上老师的头像恍然大悟,原来机缘巧合已经在微博上关注邹老师许久,一直觉得邹老师是个很有意思的人,兴趣一定十分广泛,看了老师的书确实能感觉到邹老 ...

  3. windows查看端口占用指令

    1.Windows平台 在windows命令行窗口下执行: 1.查看所有的端口占用情况 C:\>netstat -ano 协议    本地地址                     外部地址  ...

  4. 使用 Maven 管理项目

    最近的练手项目使用的是 Maven 在管理项目,在使用 Maven 管理项目时,三层的开发时分模块开发的,parent-dao-service-web,所有的spring+struts + Hiber ...

  5. webgl学习笔记四-动画

    写在前面 建议先阅读下前面我的三篇文章. webgl学习笔记一-绘图单点 webgl学习笔记二-绘图多点 webgl学习笔记三-平移旋转缩放   下面我们将讲解下如何让一个正方形动起来~不断擦除和重绘 ...

  6. 【UNIX环境高级编程】线程同步

    当多个线程共享相同的内存时,需要确保每个线程看到一致的数据视图.如果每个线程使用的变量都是其他线程不会读取和修改的,那么就不存在一致性问题.同样,如果变量是只读的也不会有一致性问题.但是,当一个线程可 ...

  7. 第146天:移动H5前端性能优化

    移动H5前端性能优化 一.概述 1. PC优化手段在Mobile侧同样适用 2. 在Mobile侧我们提出三秒种渲染完成首屏指标 3. 基于第二点,首屏加载3秒完成或使用Loading 4. 基于联通 ...

  8. windows上配置连接git

    Windows7上安装Git   我首先是百度到了这个网站:https://git-scm.com/download/win 这个网站上有下载链接,你可以根据你的系统选择不同的下载链接,我的是Win7 ...

  9. java利用poi读取excel异常问题

    最近一个web工程需要完成一个小功能,利用文件上传然后读取文件内容写入到数据库,这里是操作的excel文件,excel文件分两种后缀,03版本的xls和之后的xlsx,现在大家一般都拿非常好用的插件直 ...

  10. Django文字教程

    user-----URL对应关系-------视图函数def func1()-------------- 函数给用户返回的实质上就是一个字符串,过程:通过open函数打开HTML,把HTML读到内存中 ...