【acmm】一道简单的数学题


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】一道简单的数学题的更多相关文章
- loj#6229 这是一道简单的数学题
\(\color{#0066ff}{ 题目描述 }\) 这是一道非常简单的数学题. 最近 LzyRapxLzyRapx 正在看 mathematics for computer science 这本书 ...
- 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)} ...
- LOJ#6229. 这是一道简单的数学题(莫比乌斯反演+杜教筛)
题目链接 \(Description\) 求\[\sum_{i=1}^n\sum_{j=1}^i\frac{lcm(i,j)}{gcd(i,j)}\] 答案对\(10^9+7\)取模. \(n< ...
- loj6229 这是一道简单的数学题
https://loj.ac/problem/6229 题解:https://blog.csdn.net/Vectorxj/article/details/79094659 套路推式子,杜教筛,证明复 ...
- 【学术篇】luogu3768 简单的数学题(纯口胡无代码)
真是一道"简单"的数学题呢~ 反演题, 化式子. \[ ans=\sum_{i=1}^n\sum_{j=1}^nijgcd(i,j) \\ =\sum_{i=1}^n\sum_{j ...
- NYOJ 330 一个简单的数学题【数学题】
/* 题目大意:求解1/n; 解题思路:写一个输出小数的算法 关键点:怎样处理小数点循环输出 解题人:lingnichong 解题时间:2014-10-18 09:04:22 解题体会:输出小数的算法 ...
- 又一道简单题&&Ladygod(两道思维水题)
Ladygod Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...
- 【数学】HPU--1037 一个简单的数学题
1037: 一个简单的数学题 [数学] 时间限制: 1 Sec 内存限制: 128 MB提交: 259 解决: 41 统计 题目描述 小明想要知道$a^b$的值,但是这个值会非常的大. 所以退而求其次 ...
- 【Luogu3768】简单的数学题(莫比乌斯反演,杜教筛)
[Luogu3768]简单的数学题(莫比乌斯反演,杜教筛) 题面 洛谷 \[求\sum_{i=1}^n\sum_{j=1}^nijgcd(i,j)\] $ n<=10^9$ 题解 很明显的把\( ...
随机推荐
- unix系统内核优点
1.可靠性高 unix的可靠性2.伸缩性强 unix的伸缩性3.开放性好 unix的开放性4.网络功能强 unix的网络功能这是UNIX系统的又一重要特色,特别是作为Internet网络技术基础的TC ...
- 【week10】psp
项目 内容 开始时间 结束时间 中断时间 净时间 2016/11/19(星期六) 写博客 吉林一日游规格说明书 10:30 15:10 20 260 2016/11/20(星期日) 看论文 磷酸化+三 ...
- ci事务
CI框架百问百答:CodeIgniter的事务用法?--第9问 时间 2013-06-06 10:57:45 CSDN博客 原文 http://blog.csdn.net/haor2756/art ...
- Filter2D卷积运算
图像处理中的卷积运算一般都用来平滑图像.尖锐图像求边缘等等.主要看你选择什么样的核函数了.现在核函数很多,比如高斯平滑核函数,sobel核函数,canny核函数等等.这里举一个sobel核函数的例子来 ...
- Java多线程编程(学习笔记)
一.说明 周末抽空重新学习了下多线程,为了方便以后查阅,写下学习笔记. 有效利用多线程的关键是理解程序是并发执行而不是串行执行的.例如:程序中有两个子系统需要并发执行,这时候需要利用多线程编程. 通过 ...
- Ubuntu系统下adb devices 不能显示手机设备
1. 查看usb设备,命令:lsusb 结果如下:Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub B ...
- .net下使用NPOI读取Excel表数据
这里只写MVC下的情况 public ActionResult Index() { var path = Server.MapPath(@"/content/user.xlsx") ...
- CF464C-Substitutes in Number
题意 开始给出一个长为\(n\)的数字串,有\(m\)次操作按顺序执行,每次把当前数字串中的某一个数码替换成一个数字串\(t\)(可以为空或多位),最后问操作结束后的数字串十进制下模\(10^9+7\ ...
- C++解析(30):关于指针判别、构造异常和模板二义性的疑问
0.目录 1.指针的判别 2.构造中的异常 2.1 如果构造函数中抛出异常会发生什么? 2.2 如果析构函数中抛出异常会发生什么? 3.令人迷惑的写法 3.1 模板中的二义性 3.2 函数异常声明 4 ...
- python基础(5)
使用dict和set dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例子 ...