UVa 10655 - Contemplation! Algebra
来源:互联网 发布:像一世之尊的小说知乎 编辑:程序博客网 时间:2024/05/16 12:39
初学矩阵 , 还没有习惯用矩阵的思路考虑问题 , 但貌似这个题不用矩阵思路更简单
提示:
1. 如何用a^( n/2 )+b^( n/2 ) 表示 a^n + b^n 呢
注意: 不能够使用unsigned long long 代替 long long , 答案可能是负数(因为a , b可能是虚数)
//// main.cpp// UVa10655//// Created by Fuxey on 15/10/25.// Copyright © 2015年 corn.crimsonresearch. All rights reserved.//#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <vector>#include <deque>#include <string>#include <list>#include <queue>#include <set>#include <map>#include <algorithm>using namespace std;typedef long long ull;ull p , q , n;ull powMul(ull n){ if(n==1) return q; ull ans = powMul(n/2); if(n%2) return ans*ans*q; else return ans*ans;}ull powAnd(ull n){ if(n==1) return p; else if(n==0) return 2; ull halfs = powAnd(n/2); if(n%2) { ull others = powAnd(n/2+1); return others*halfs-powMul(n/2)*p; } else return halfs*halfs-2*powMul(n/2);}int main(int argc, const char * argv[]) { while(cin>>p>>q>>n) cout<<powAnd(n)<<endl; return 0;}
0 0
- UVA 10655 Contemplation! Algebra
- UVA 10655 Contemplation! Algebra
- UVa 10655 - Contemplation! Algebra
- UVA 10655 Contemplation! Algebra
- uva 10655 Contemplation! Algebra 矩阵快速幂
- UVA 10655 Contemplation! Algebra(矩阵乘法)
- UVA 10655 - Contemplation! Algebra(矩阵快速幂)
- uva 10655 - Contemplation! Algebra(矩阵快速幂)
- UVA-10655 Contemplation! Algebra (矩阵快速幂)
- UVA 10655 Contemplation! Algebra(构造矩阵)
- UVA 10655 Contemplation! Algebra(矩阵乘法)
- Contemplation! Algebra UVA
- UVA 10655 Contemplation! Algebra(矩阵快速幂)
- UVA 10655 Contemplation! Algebra (矩阵快速幂)
- UVA 10655 Contemplation! Algebra(构造矩阵和快速幂)
- uva 10655 Contemplation! Algebra(矩阵快速幂)
- uva 10655 Contemplation! Algebra(矩阵快速幂)
- uva 10655 - Contemplation! Algebra 【矩阵快速幂】【最坑的输入】
- vagrant virtualbox VM inaccessible解决办法
- 机房收费系统之用例图
- 如何写一个.properties文件
- Xcode7.1 App上线提交不了问题汇总
- LEETCODE-Rectangle Area
- UVa 10655 - Contemplation! Algebra
- 欢迎使用CSDN-markdown编辑器
- bzoj3391: [Usaco2004 Dec]Tree Cutting网络破坏
- 二、计算机程序
- 数据结构实践项目——树和二叉树(1)
- ubuntu chrome安装
- 3、APPSCAN IBM的安全性测试引擎
- View动画另一些使用场景--LayoutAnimation和Activity之间的切换效果
- 第一次机房收费系统之导出到Excel