Alex and Number

时间限制: 1 Sec  内存限制: 128 MB
提交: 69  解决: 12
[提交][状态]

题目描述

Alex love Number theory. Today he think a easy problem, Give you number N and L, To calculate N^1 + N^2 + N^3 + ... + N^L, And ans will mod 1e9+7

输入

Many test of input(about 10W case), each input contains number N and L, 1 <= N, L <= 2147483647

输出

Contains a number with your answer

样例输入

2 5
3 5
10 10

样例输出

62
363
111111033 discuss:1e9+7,数好大有木有,2147483647的2147483647是多少~
point:快速幂
#include<iostream>
#include<cstring>
#include<cstring>
#include<cstdio> using namespace std; const int MOD = ; // 宏定义也行 typedef long long ll; // __int64也行 ll pow_mod(ll x, ll k) // 快速幂函数
{
ll ans = ; if(k == )
return x;
while(k)
{
if(k&)
ans = (ans * x) % MOD;
        x = (x * x) % MOD;
k >>= ; // k /= 2
}
return ans;
 //     (n*n*n*n*n)%Mod = (( ((n*n)%Mod) *((n*n)%Mod) ) % Mod) * (n % Mod) ,记住就行了~至于为什么,目前我还不知道
} ll magic(ll n, ll l)
{
if(l == )
return n; ll tmp = magic(n, l/); // 递归,二分,先求l部分的前一半项 ll ste = (tmp + (pow_mod(n, l/) * tmp )% MOD) % MOD; // n+n*n+n*n*n+n*n*n*n = n+n*n + (n+n*n) * n * n(L个 if(l&)
ste = (ste + (pow_mod(n, l) % MOD)) % MOD; // 如果l是奇数,加上最后一项,即n的l次方
return ste; // 返回当前l项的结果
} int main()
{
ll n, l; while(~scanf("%lld%lld", &n, &l))
{
printf("%lld\n", magic(n, l));
}
return ;
}

最新文章

  1. python autopep8
  2. SQL中以count及sum为条件的查询
  3. S3C2440的GPIO
  4. EasyUI - SearchBox 搜索框
  5. ES6的介绍和常用语法
  6. 5.Flask-Migrate
  7. UOJ#407. 【IOI2018】狼人 Kruskal,kruskal重构树,主席树
  8. mybatis使用&lt;choose&gt; &lt;when&gt;
  9. fatal: unable to access &#39;https://github.com/open-falcon/falcon-plus.git/&#39;: Peer reports incompatible or unsupported protocol version
  10. 【第五课】LNMP环境的入门
  11. 倒计数锁存器(CountDown Latch)和 CyclicBarrier(同步屏障)
  12. CentOS7无法使用tab补全功能??
  13. P2015 二叉苹果树
  14. 配置NGINX支持中文URL 中文文件名称或文件夹404无法訪问的解决方法
  15. [Python]网络爬虫(七):Python中的正则表达式教程(转)
  16. python list内部功能记录
  17. BZOJ 2152 聪聪可可(树形DP)
  18. 【Java】常用POI生成Excel文档设置打印样式
  19. [BZOJ1044木棍分割]
  20. Canvas开发库封装

热门文章

  1. jmeter测试https请求
  2. SPSS输出结果如何在word中设置小数点前面显示加0
  3. git如何撤销工作区的修改
  4. Grafana 下载与安装(v5.4.1)
  5. Learn Python the hard way, ex39 列表的操作
  6. hdu1257最少拦截系统 动态规划(最长递增子序列(LIS))
  7. python中map函数和reduce函数的区别
  8. oracle存储过程调试-plsql
  9. 点分治题单(来自XZY)
  10. python学习第五天流程控制分支if和循环while