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