【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$ 题解 很明显的把\( ...
随机推荐
- spring-test与junit
1.添加依赖 spring-test junit spring-context(自动添加依赖其他所需的spring依赖包) 2.在class前添加以下注解,用于配置xml文件的位置 @RunWith( ...
- C语言语法树
- Objective - C 之协议
一.创建方法: 二.实现过程: 1.遵循协议: @protocol NurseWorkingProtocol <NSObject> //<> 表示遵守协议,创建时就有(Nu ...
- 【第一周】第一周工作统计(psp)
项目:词频统计 项目类型:个人项目 项目完成情况:已完成 项目改进:未变更 项目日期:2016.9.3-2016.9.4 3号 类别c 内容c 开始时间s 结束e 中断I 净时间T 项目实践 构思 ...
- webpack打包多html开发案例
简单说明: 1,案例没有使用devserver,所以不能实时查看 2,案例是将src下面的html.css.js分别进行处理 3,多html的规律是需要有多个entry,每个html一个entry,当 ...
- jetty之maven配置
<!-- jetty 插件配置 --><plugin> <groupId>org.mortbay.jetty</groupId> <artifac ...
- 【bzoj4355】Play with sequence 线段树区间最值操作
题目描述 维护一个长度为N的序列a,现在有三种操作: 1)给出参数U,V,C,将a[U],a[U+1],...,a[V-1],a[V]都赋值为C. 2)给出参数U,V,C,对于区间[U,V]里的每个数 ...
- 转:评估指标MAP
转:http://www.zhenv5.com/?p=1079 MAP可以由它的三个部分来理解:P,AP,MAP 先说P(Precision)精度,正确率.在信息检索领域用的比较多,和正确率一块出现的 ...
- C++11线程使用总结
std::thread 在 <thread> 头文件中声明,因此使用 std::thread 需包含 <thread> 头文件. <thread> 头文件摘要 &l ...
- hdu1693 Eat the Trees 【插头dp】
题目链接 hdu1693 题解 插头\(dp\) 特点:范围小,网格图,连通性 轮廓线:已决策点和未决策点的分界线 插头:存在于网格之间,表示着网格建的信息,此题中表示两个网格间是否连边 状态表示:当 ...