LIGHT OJ1070 Algebraic Problem
题目:
Given the value of a+b and ab you will have to find the value of a^n+b^n. a and b not necessarily have to be real numbers.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains three non-negative integers, p, q and n. Here p denotes the value of a+b and q denotes the value of ab. Each number in the input file fits in a signed 32-bit integer. There will be no such input so that you have to find the value of 00.
Output
For each test case, print the case number and (an+bn) modulo 264.
大意:
给定数字a,b的乘积q,a与b的和p;求(a^n+b^n)%2^64;
解法:
直接用unsigned long long 可以解决%2^64的问题,剩下直接套用矩阵快速幂求解;
代码如下:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define maxn 100007
using namespace std;
typedef unsigned long long ull;
struct mat
{ull val[5][5];
};
mat matmult(mat a,mat b)
{mat ms;memset(ms.val,0,sizeof(ms.val));for(int i=1;i<=2;i++){for(int j=1;j<=2;j++){for(int k=1;k<=2;k++){ms.val[i][j]+=a.val[i][k]*b.val[k][j];}}}return ms;
}
mat matpow(mat a,ull k)
{mat ans;memset(ans.val,0,sizeof(ans.val));for(int i=1;i<=2;i++)ans.val[i][i]=1;while(k){if(k&1)ans=matmult(a,ans);a=matmult(a,a);k>>=1;}return ans;
}
int main()
{int t;scanf("%d",&t); int cas=0;while(cas<t){cas++;ull p,q,n;scanf("%llu%llu%llu",&p,&q,&n);mat ans;if(n==0){printf("Case %d: ",cas);puts("2");continue;}if(n==1){printf("Case %d: %llu\n",cas,p);continue;}ans.val[1][1]=p;ans.val[2][1]=1;ans.val[1][2]=-q;ans.val[2][2]=0;ans=matpow(ans,n-1);ull res=ans.val[1][1]*p+ans.val[1][2]*2;printf("Case %d: %llu\n",cas,res);}return 0;
}
LIGHT OJ1070 Algebraic Problem相关推荐
- LOJ 1070 Algebraic Problem
LOJ 1070 Algebraic Problem 题目链接:Light OJ 1070 Algebraic Problem Problem Description Given the value ...
- LightOJ 1070 Algebraic Problem (推导+矩阵快速幂)
题目链接:LightOJ 1070 Algebraic Problem 题意:已知a+b和ab的值求a^n+b^n.结果模2^64. 思路: 1.找递推式 得到递推式之后就是矩阵快速幂了 注意:模2^ ...
- [LightOJ1070]Algebraic Problem
题目:Algebraic Problem 链接:https://vjudge.net/problem/LightOJ-1070 分析: 1)$ a^n+b^n = ( a^{n-1}+b^{n-1} ...
- list下界_下界理论
list下界 下界理论 (Lower Bound Theory) Lower bound (L(n)) is a property of the specific problem i.e. the s ...
- [E]PSM算法简析
转自: http://www.graphicsgeeks.org/index.php?title=PSM&oldid=153 (图形学极客) 参照:http://www.opengpu.org ...
- i219v微星 驱动_适用于WinPE的I219V英特尔驱动程序
存储在NAS中的备份文件,并将启动映像发送到客户端(客户端与服务器的型号相同),以便PXE引导和映像或恢复其驱动器. 轻松的工作. 问题是驱动程序支持. 由于我有很多时间,我测试了尽可能多的解决方案来 ...
- 科技 人文_以人文个性化应对认识论的不公正
科技 人文 Machine learning-backed personalized services have become a permanent fixture in our increasin ...
- 新视野大学英语读写教程(第二版 第三册)读写教程答案(4-9)单元
第二版新视野大学英语读写教程第三册unit4答案 Unit 4 III 1. inspected 2. assembled 3. exaggerated 4. versions 5. universa ...
- 当代数学大师迈克尔阿蒂亚证明黎曼猜想
去9月24日,89岁高龄的当代数学大师迈克尔阿蒂亚先生亲自前往海德堡高级数学论坛公开证明黎曼猜想,此举吸引了全球数学界的目光. 阿蒂亚指出:黎曼猜想的核心问题是素数分布定理,两者关系密切.国人对此事件 ...
最新文章
- P4113 [HEOI2012]采花 树状数组离线
- curl 与 header 及 file_get_countents 访问内容时的区别
- oracle 动态sql列转行_oracle行转列(动态行转不定列)
- Regex Tester (免费有用)
- 使用 Azure Function 定时启动云 VM
- ie 调用java的时候报错,调用javabean的非常郁闷的异常。
- pytorch之with torch.no_grad
- (二叉树的动态创建与bfs)树的层次遍历
- 3d建模电脑配置要求_建模你会一个软zbrush够吃一辈子,你学会了吗?
- java se development kit可以卸载吗_首款纯电版MINI COOPER详细评测,或将国产,值得等吗?...
- Spring事物管理(二)
- python和java学哪个好-Python和Java学哪个好?大家是怎么选的
- 自定义 Cordova插件(基础篇)
- 案例4-2 树种统计 (25 分)(map映射)
- 全球国家(和地区)信息JSON数据
- 国人走向世界的一个很好的艺术与设计网站
- 【基础知识】Dom基础
- 怎么判断两个多项式互素_多项式互素性质的补充讨论
- Java,Axis方式调用WebService接口,支持多参数
- 编译可在Android上运行的qemu
热门文章
- 「RPA商战风云」从这次农行总部招标说起
- IEC 61131标准系列
- MySQL设置utf8mb4编码
- 歪解:备份BlackBerry手机上面的安装好的程序(cod)
- python爬虫你们最爱的YY小姐姐,这不爬取下来看看?
- 转帖——李开复:我的大学生活琐忆
- yan-master项目集成Activiti 6.0.0
- asp.net web快速开发mvc网站框架源码
- 皇家贝贝骗子佟大为赴内蒙出席活动 影迷冒严寒守候支持
- tooth的用法_tooth是什么意思_tooth的翻译_音标_读音_用法_例句_爱词霸在线词典