ZSTU 3194 复数的幂 二分幂
2012-12-16 14:38
225 查看
递归
View Code
View Code
#include <cstdio> #include <cstring> #define LL __int64 LL a, b, n, mod; struct complex { LL a, b; complex(){} complex(LL a, LL b):a(a%mod),b(b%mod){} complex operator *(const complex &p) { return complex((a*p.a-b*p.b)%mod, (a*p.b+b*p.a)%mod); } }; void gao(LL n, complex &p) { if(n == 1) { p = complex(a%mod, b%mod); return; } complex q; gao(n>>1, q); p = q * q; if(n & 1) { complex t = complex(a%mod, b%mod); p = p * t; } } int main() { int i, j; while( ~scanf("%I64d%I64d%I64d%I64d", &a, &b, &n, &mod)) { if(!n) { printf("1 0\n"); continue; } complex p; gao(n, p); if(p.a < 0) p.a += mod; if(p.b < 0) p.b += mod; printf("%I64d %I64d\n", p.a, p.b); } return 0; }
相关文章推荐
- ZSTU 3194 复数的幂 二分幂
- java求复数四则运算,习题5.23(最终版)
- 英语复数名词的变化规则
- 名词单数变复数规则
- 关于英语单词单复数转换方法在程序中的实现
- 理解离散傅立叶变换(三)------复数
- 复数的加减运算
- zstu 1052 水题。。模拟
- 第七周任务三 类模板 复数
- C++运算符重载(以复数为例)
- 类模板实现复数运算的基本操作
- C99 标准对复数类型和复数运算的支持
- Hadoop中自定义Writable类型(FFT中复数)
- 浙江理工ZSTU 2853 计算表达式的值
- 对复数进行的+-*/运算符重载
- 第7周项目4复数类
- zstu 4111 Bread Sorting 线段树求逆序数
- 求复数的平均值
- 线性代数导论27——复数矩阵和快速傅里叶变换
- 使用C#版本GDAL读取复数图像