LOJ 1070 Algebraic Problem

题目链接:Light OJ 1070 Algebraic Problem


Problem Description

Given the value of a+b and ab you will have to find the value of an+bna^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 000^0.

Output

For each test case, print the case number and(an+bn) (a^n+b^n) modulo 2642^{64}.

Sample Input

2
10 16 2
7 12 3

Sample Output

Case 1: 68
Case 2: 91

题意:

给出p=a+b的值和q=ab的值,求(an+bn)(a^n+b^n)%2642^{64},(p,q,n都是32位有符号的数)

AC代码:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <locale>
#include <vector>
#include <string>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>using namespace std;int nnn=2;struct juzhen
{unsigned long long x[3][3];
}e,a,b,t;juzhen multi(juzhen A,juzhen B)
{juzhen c;memset(c.x,0,sizeof(c.x));for(int i=1; i<=nnn; i++)for(int j=1; j<=nnn; j++)for(int k=1; k<=nnn; k++)c.x[i][j]+=A.x[i][k]*B.x[k][j];return c;
}juzhen quick(unsigned long long nn)
{juzhen A=a,B=e;while(nn>0){if(nn&1)B=multi(B,A);nn>>=1;A=multi(A,A);}return B;
}int main()
{int T;scanf("%d",&T);for(int i=1; i<=T; i++){unsigned long long p,q,n;scanf("%llu%llu%llu",&p,&q,&n);memset(e.x,0,sizeof(e.x));memset(a.x,0,sizeof(a.x));memset(b.x,0,sizeof(b.x));for(int j=1;j<=nnn;j++)e.x[j][j]=1;a.x[1][1] = p;a.x[1][2] = -q;a.x[2][1] = 1;b.x[1][1] = p;b.x[2][1] = 2;if(!n){printf("Case %d: 2\n",i);continue;}t=quick(n-1);t=multi(t,b);printf("Case %d: %llu\n",i,t.x[1][1]);}return 0;
}

LOJ 1070 Algebraic Problem相关推荐

  1. LightOJ 1070 Algebraic Problem (推导+矩阵快速幂)

    题目链接:LightOJ 1070 Algebraic Problem 题意:已知a+b和ab的值求a^n+b^n.结果模2^64. 思路: 1.找递推式 得到递推式之后就是矩阵快速幂了 注意:模2^ ...

  2. [LightOJ1070]Algebraic Problem

    题目:Algebraic Problem 链接:https://vjudge.net/problem/LightOJ-1070 分析: 1)$ a^n+b^n = ( a^{n-1}+b^{n-1} ...

  3. 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 necessaril ...

  4. Loj 6036 「雅礼集训 2017 Day4」编码 - 2-sat

    题目传送门 唯一的传送门 题目大意 给定$n$个串,每个串只包含 '0','1','?' ,其中 '?' 至多在每个串中出现1次,它可以被替换为 '0' 或 '1' .问是否可能任意两个不同的串不满足 ...

  5. 当代数学大师迈克尔阿蒂亚证明黎曼猜想

    去9月24日,89岁高龄的当代数学大师迈克尔阿蒂亚先生亲自前往海德堡高级数学论坛公开证明黎曼猜想,此举吸引了全球数学界的目光. 阿蒂亚指出:黎曼猜想的核心问题是素数分布定理,两者关系密切.国人对此事件 ...

  6. list下界_下界理论

    list下界 下界理论 (Lower Bound Theory) Lower bound (L(n)) is a property of the specific problem i.e. the s ...

  7. LOJ 2721 「NOI2018」屠龙勇士——扩展中国剩余定理

    题目:https://loj.ac/problem/2721 1.注意别一输入 p[ i ] 就 a[ i ] %= p[ i ] ,因为在 multiset 里找的时候还需要真实值. 2.注意用 m ...

  8. Loj #6287 诗歌

    link: https://loj.ac/problem/6287 一开始差点写FFT了23333,并且FFT还能算这样的三元组的数量而且还不用要求这是一个排列.... 但这太大材小用了(而且很可能被 ...

  9. Loj #2036. 「SHOI2015」自动刷题机

    link : https://loj.ac/problem/2036 这个显然具有单调性,N小的话更容易A题,不仅因为A一次题减少的代码,并且A题的下限也低. 所以直接上二分就行了,注意上限一定不要设 ...

最新文章

  1. linux安装redis教程yum,linux下yum安装redis以及使用
  2. ai的预览模式切换_绝对高级!AI打造超酷矩阵纬度文字效果!
  3. php怎么做签到系统,PHP如何实现签到功能
  4. 万物智联时代的终端智能「管家」重磅升级:混合云IoT一体机
  5. 图像基本处理算法的简单实现(二)
  6. 学习SQL数据查询,这一篇就够了!
  7. php七牛持久化处理,使用七牛自定义数据处理范例
  8. 《SQL高级应用和数据仓库基础(MySQL版)》学习笔记 ·010【高级查询】
  9. python distance matrix_Python 矩阵转置的几种方法小结
  10. matlab 加权残值法,分步迭代加权残值法
  11. 麻省理工的服务器位置,美国麻省理工学院的地理位置
  12. 【超硬核】秒杀活动技术方案,Redis申请32个G,被技术总监挑战了...
  13. 【华为机试】HJ16 购物单
  14. 区块链+能源:乌托邦愿景还是未来蓝图?
  15. 腾讯安全发布《2020年上半年手机安全报告》,揭示手机安全四大趋势
  16. 【jenkins】jenkins旧版本下载
  17. docker容器启动后无法访问宿主机host
  18. Java多线程编程——线程同步与线程安全问题及synchronized关键字
  19. redenvelope php,微信免越狱抢红包速成手册
  20. python安全攻防第三章之Poc

热门文章

  1. linux内核声卡管理,浅析linux 2.6.30.4内核中uda134x声卡驱动源码 - audio和bluetooth
  2. 电脑换cpu要重装系统吗
  3. 应届毕业生到底有哪些优势呢
  4. TcpDump使用手册
  5. 2020 CES:美团和法雷奥合作无人配送车
  6. 给自己的软件添加数字签名数字签名格式转换
  7. 【PC】【抓包】PC抓取vlan报文的方法
  8. Simpsons’ Hidden Talents HDU - 2594
  9. RAR Extractor - The Unarchiver Pro for mac(解压缩软件)v6.3.5激活版
  10. 2021年茶艺师(高级)考试资料及茶艺师(高级)复审考试