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的更多相关文章

  1. Go-day05

    今日概要: 1. 结构体和方法 2. 接口 一.go中的struct 1. 用来自定义复杂数据结构 2. struct里面可以包含多个字段(属性) 3. struct类型可以定义方法,注意和函数的区分 ...

  2. 13 并发编程-(线程)-异步调用与回调机制&进程池线程池小练习

    #提交任务的两种方式 #1.同步调用:提交完任务后,就在原地等待任务执行完毕,拿到结果,再执行下一行代码,导致程序是串行执行 一.提交任务的两种方式 1.同步调用:提交任务后,就在原地等待任务完毕,拿 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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) ...

  7. 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 ...

  8. 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 ...

  9. 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   ...

随机推荐

  1. Python的Django框架中的URL配置与松耦合

    Python的Django框架中的URL配置与松耦合 用 python 处理一个文本时,想要删除其中中某一行,常规的思路是先把文件读入内存,在内存中修改后再写入源文件. 但如果要处理一个很大的文本,比 ...

  2. Android深度探索-卷1第七章心得体会

    创建LED驱动的设备文件 第一步:使用cdev_init函数初始化cdev 第二步:指定设备号.直接在代码指定或动态分配 第三步:使用cdev_add函数将字符设备添加到内核中的字符设备数组中 第四步 ...

  3. ruby基本语法(2)

    关于数组 Ruby数组中的数据类型可以不相同并且长度也是可变的.(好聪明啊感觉用的久了就会变笨了,除非你本来就是老手)比如下面的例子 Myarray=[1,2,“ruby”] Ruby也支持那种-1的 ...

  4. python的前景

    最近几年Python编程语言在国内引起不小的轰动,有超越Java之势,本来在美国这个编程语言就是最火的,应用的非常非常的广泛,而Python的整体语言难度来讲又比Java简单的很多.尤其是在运维的应用 ...

  5. Array.prototype.includes

    if (!Array.prototype.includes) {   Array.prototype.includes = function(searchElement /*, fromIndex*/ ...

  6. 广播模式下的生产者与消费者fanout模式

    生产者 #coding=utf-8 import pika import sys connection = pika.BlockingConnection(pika.ConnectionParamet ...

  7. css样式表的引入方式

    一般来说,css 有两种样式表的引入方式,在这里我记录一下,比较这两种引入方式的区别: <link rel="stylesheet" type="text/css& ...

  8. 实现combobox模糊查询的时候报错 InvalidArgument=“0”的值对于“index”无效

    因为要对combobox实现模糊查询,因为系统实现的匹配只能从左到右进行匹配,所以利用两个list来进行模糊匹配,主要代码如下: List<string> listOnit = new L ...

  9. vue.js(7)--vue中的样式绑定

    vue中class样式与内联样式的绑定 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  10. 解决嵌套在ScrollView中的TableView滑动手势冲突问题

    最近在迭代开发公司项目的时候遇到了一个问题,在可以左右切换标签视图的ScrollView中嵌套了两个TableView用于展示视图,感觉一切so easy的情况下,问题出现了,因为左右两个视图既可以实 ...