Alex and Number
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 ;
}
Alex and Number的更多相关文章
- Go-day05
今日概要: 1. 结构体和方法 2. 接口 一.go中的struct 1. 用来自定义复杂数据结构 2. struct里面可以包含多个字段(属性) 3. struct类型可以定义方法,注意和函数的区分 ...
- 13 并发编程-(线程)-异步调用与回调机制&进程池线程池小练习
#提交任务的两种方式 #1.同步调用:提交完任务后,就在原地等待任务执行完毕,拿到结果,再执行下一行代码,导致程序是串行执行 一.提交任务的两种方式 1.同步调用:提交任务后,就在原地等待任务完毕,拿 ...
- From MSI to WiX, Part 4 - Features and Components by Alex Shevchuk
Following content is directly reprinted from : http://blogs.technet.com/b/alexshev/archive/2008/08/2 ...
- From MSI to WiX, Part 2 - ARP support, by Alex Shevchuk
Following content is directly reprinted from From MSI to WiX, Part 2 - ARP support Author: Alex Shev ...
- From MSI to WiX, Part 1 - Required properties, by Alex Shevchuk
Following content is directly reprinted from From MSI to WiX, Part 1 - Required properties Author: A ...
- MySQL Error Number 1005 Can’t create table(Errno:150)
mysql数据库1005错误解决方法 MySQL Error Number 1005 Can’t create table ‘.\mydb\#sql-328_45.frm’ (errno: 150) ...
- CodeForces - 1097F:Alex and a TV Show (bitset & 莫比乌斯容斥)
Alex decided to try his luck in TV shows. He once went to the quiz named "What's That Word?!&qu ...
- NBUT校赛 J Alex’s Foolish Function(分块+延迟标记)
Problem J: Alex’s Foolish Function Time Limit: 8 Sec Memory Limit: 128 MB Submit: 18 Solved: 2 Des ...
- ACM程序设计选修课——1040: Alex and Asd fight for two pieces of cake(YY+GCD)
1040: Alex and Asd fight for two pieces of cake Time Limit: 1 Sec Memory Limit: 128 MB Submit: 27 ...
随机推荐
- 测开之路七十三:用kafka实现消息队列之环境搭建
一:装java环境,确保java能正确调用 kafka下载地址:http://kafka.apache.org/downloads 下载并解压kafka: 新建两个文件夹,用于存放zookeeper和 ...
- jvm 更多链接
http://www.cnblogs.com/dingyingsi/p/3760447.html : 讲解 jvm https://blog.csdn.net/Luomingkui1109/a ...
- Oracle基本操作练习(一)
--创建表空间 create tablespace test datafile 'c:\test.dbf' size 100m autoextend on next 10m; --删除表空间 drop ...
- StringBuilder -字符串缓冲区,节约内层空间变长数组
package cn.learn; /* 字符串缓冲区 -缓冲可提高效率 java.lang.StringBuilder 字符串的底层是一个被final修饰的数组,不能改变,是一个常量 private ...
- BZOJ 4675(点分治)
题面 传送门 分析 由于期望的线性性,我们可以分别计算每个点对对答案的贡献 有三个人取数字,分开对每个人考虑 设每个人分别取了k个数,则一共有\(C_n^k\)种组合,选到每种组合的概率为\(\fra ...
- python学习第二十六天非固定参数几种情况
python函数参数传递,位置参数,默认参数,关键词参数,最后介绍一个非固定参数,就可以向函数传递一个列表,元组,字典,具体看看用法 1,有一个* 号的参数情况 def goos_stu(id,*us ...
- 阿里云ECS服务安装 nginx+php+MariaDB完整版
安装 Nginx想在 CentOS 系统上安装 Nginx ,你得先去添加一个资源库,像这样: vim /etc/yum.repos.d/nginx.repo使用 vim 命令去打开 /etc/yum ...
- 2. ZooKeeper基础
1. ZooKeeper的特性 ZooKeeper的特性主要从会话.数据节点,版本,Watcher,ACL权限控制,集群角色这些部分来了解,其中需要重点掌握的数据节点与Watcher 1.1 会话 客 ...
- Python内置函数(19)-slice
官方文档 class slice(stop) class slice(start, stop[, step]) Return a slice object representing the set o ...
- python常用函数 R
replace(str, str) 字符串替换. 例子: rjust(int) 格式化字符串,右对齐,支持传入填充值. 例子: rstrip(str) 删去右边的参数,支持传入参数. 例子: roun ...