POJ 3012 : A Number from Yanghui Triangle - 快速幂;推公式
2015-01-10 21:45
405 查看
用到快速幂的模版
然后推公式
((1+10^k)^n)%m
#include <iostream>
#include <stdio.h>
using namespace std;
#define LL long long
LL qm(LL a,LL k,LL m)
{
LL re=1,y=a%m;
for(;k;k>>=1,y=y*y%m) if(k&1ll) re=y*re%m;
return re;
}
LL n,k,m;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%lld",&n,&k,&m);
printf("%lld\n",qm(qm(10,k,m)+1,n,m));
}
return 0;
}
然后推公式
((1+10^k)^n)%m
3012 | Accepted | 700K | 735MS | G++ | 358B |
#include <stdio.h>
using namespace std;
#define LL long long
LL qm(LL a,LL k,LL m)
{
LL re=1,y=a%m;
for(;k;k>>=1,y=y*y%m) if(k&1ll) re=y*re%m;
return re;
}
LL n,k,m;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%lld",&n,&k,&m);
printf("%lld\n",qm(qm(10,k,m)+1,n,m));
}
return 0;
}
相关文章推荐
- poj 3021 A Number from Yanghui Triangle
- poj 3696 The Luckiest number(欧拉函数+快速幂取模)
- POJ 1845-Sumdiv(快速幂取模+整数唯一分解定理+约数和公式+同余模公式)
- poj 3696 The Luckiest number——数论 (快速幂取模,乘法取模模版)
- POJ 1845-Sumdiv(快速幂取模+整数唯一分解定理+约数和公式+同余模公式)
- POJ 3696 : The Luckiest number - 欧拉函数,快速幂[数论好题]
- poj 3696 The Luckiest number (数论-快速幂+欧拉定理)
- 1423 poj Big Number 公式题
- POJ 1845 Sumdiv (快速幂+质因数+约数和公式+同余模)
- Multi select elements which sums upto a certain number from an array(II)
- POJ1023 The Fun Number System
- [转帖]快速计算某个日期是星期几的经验公式
- oracle 数字格式转换 select to_number('$8,000.80','$999,999,999.99') from dual;
- POJ Ugly number
- Multi select elements which sums upto a certain number from an array(II)
- POJ 2030 The Secret Number
- 使用 DB2 的 LOAD FROM CURSOR 特性快速轻松地转移数据 (From IBM developerWorks )
- POJ 1220 NUMBER BASE CONVERSION
- oracle 数字格式转换 select to_number('$8,000.80','$999,999,999.99') from dual;
- Get number from string with regular expression in java