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. 测开之路六十二:接口测试平台之公共的js、html、平台入口

    common.js //定义后台的host和端口var host = 'http://192.168.xxx.1:8000'; //'http://127.0.0.1:8000'; //用于发送htt ...

  2. python实现基于两张图片生成圆角图标效果的方法

    python实现基于两张图片生成圆角图标效果的方法 这篇文章主要介绍了python实现基于两张图片生成圆角图标效果的方法,实例分析了Python使用pil模块进行图片处理的技巧,分享给大家供大家参考. ...

  3. 工具使用-curl/wget

    curl curl -v www.test.com -H -/MS15- curl -x .xx: http://test.com #使用代理访问 wget wget -e “http_proxy=. ...

  4. #C语言l作业04

    这个作业属于哪个课程** C语言程序设计ll 这个作业的要求 (https://edu.cnblogs.com/campus/zswxy/SE2019-4/homework/9776) 我在这个课程的 ...

  5. vue配置域名访问

    vue配置域名访问其实很简单,新建一个vue的项目,不废话,直接上截图 红色框住的两行就是设置访问的域名以及端口,默认是host: localhost port: 8080 像这样修改之后,重启项目, ...

  6. [已解决]报错: Windows下Redis服务无法启动,错误 1067 进程意外终止解决方案

    启动redis时出现的报错内容: 解决方法: 找到登录状态 如果是网络服务,直接双击此服务,修改为本地系统服务即可启动!

  7. stl(优先队列操作)

    http://codeforces.com/gym/101911/problem/C Recently Monocarp has created his own mini-laboratory! Th ...

  8. Linux忘记密码怎么办

    重启 Linux 系统主机并出现引导界面时,按下键盘上的 e 键进入内核编辑界面 在 linux16 参数这行的最后面追加"rd.break"参数,然后按下 Ctrl + X 组合 ...

  9. P2469 [SDOI2010]星际竞速(费用流)

    P2469 [SDOI2010]星际竞速 最小路径覆盖问题 每个星球必须恰好去一次,而每次高速航行都是从一个星球到另一个星球. 那么高速航行的起点可以保证被去过 高速航行和空间跳跃可以是互相独立的 将 ...

  10. C#中XmlTextWriter读写xml文件详细介绍

    XmlTextWriter类允许你将XML写到一个文件中去.这个类包含了很多方法和属性,使用这些属性和方法可以使你更容易地处理XML.为了使用这个类,你必须首先创建一个新的XmlTextWriter对 ...