【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$ 题解 很明显的把\( ...
随机推荐
- BETA预发布演示视频
视频连接:优酷http://v.youku.com/v_show/id_XMTgxMjQxMjc0NA==.html?from=y1.7-2
- maven Web项目中POM的配置信息
什么是POM? POM是项目对象模型(Project Object Model)的简称,它是Maven项目中的文件,使用XML表示,名称叫做pom.xml.在Maven中,当谈到Project的时候, ...
- [LeetCode] Search in Rotated Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- 第111天:Ajax之jQuery实现方法
由于jQuery中的Ajax方法是用了内置的deferred模块,是Promise模式的一种实现,而我们这里没有讲过,所以我们就不使用这一模式啦. 我们只定义一个Ajax方法,他可以简单的get,po ...
- 矩阵快速幂模板(pascal)
洛谷P3390 题目背景 矩阵快速幂 题目描述 给定n*n的矩阵A,求A^k 输入输出格式 输入格式: 第一行,n,k 第2至n+1行,每行n个数,第i+1行第j个数表示矩阵第i行第j列的元素 输出格 ...
- BZOJ4972 小Q的方格纸
每个格子记录其左下的45°直角梯形区域的和及左下矩形区域的和即可. #include<iostream> #include<cstdio> #include<cmath& ...
- [洛谷P4626]一道水题 II
题目大意:求$lcm(1,2,3,\cdots,n)\pmod{100000007}$,$n\leqslant10^8$ 题解:先线性筛出质数,然后求每个质数最多出现的次数,可以用$\log_in$来 ...
- 【Revit API】Revit读取当前rvt的所有视图与其名称
1)读取所有视图: public static ViewSet GetAllViews(Document doc) { ViewSet views = new ViewSet(); FilteredE ...
- 【BZOJ2141】排队(树套树)
[BZOJ2141]排队(树套树) 题面 BZOJ 洛谷 题解 傻逼题啊... 裸的树套树 树状数组套线段树,每次交换的时候,考虑一下前后的贡献,先删掉贡献,再重新算一遍就好了.. #include& ...
- C++操作Windows WIFI
原文链接地址:https://blog.csdn.net/just_do_1122/article/details/78031024 实现功能 无线网卡列表 无线热点扫面 无线 ...