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. Jmeter接口测试报告模板优化

    优化后在接口报告的接口信息中,直接展示url,method,结果和响应时间,详情中展示请求和响应数据.具体如下: 模板文件 jmeter-results-detail-report_21.xsl: & ...

  2. Selenium WebDriver Log4j打印执行日志

    在自动化测试脚本的执行过程中,使用log4j在日志文件中打印执行日志,用于监控和后续调试脚本. Log4j.xml 文件 <log4j:configuration xmlns:log4j=&qu ...

  3. HeightCharts柱状图和饼状图

    HTML: <div id="container1"  style="height:350px; " ></div>    <di ...

  4. stl应用(map)或字典树(有点东西)

    M - Violet Snow Gym - 101350M Every year, an elephant qualifies to the Arab Collegiate Programming C ...

  5. dp(最长公共上升子序列)

    This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence ...

  6. luoguP2123 皇后游戏(贪心)

    luoguP2123 皇后游戏(贪心) 题目 洛谷题目chuanso 题解 有一篇好题解,我就懒得推式子了,毕竟打到电脑上还是很难的 牛逼题解传送门 code #include<iostream ...

  7. 03 synchronized

    synchronized 1. 锁机制的特性 互斥性:在同一时间只允许一个线程持有某个对象锁(原子性) 可见性:必须确保在锁被释放之前,对共享变量所在的修改,对于随后获得该锁的另一个线程是可见的 2. ...

  8. [原]Threads vs Processes in Linux 分析

    Linux中thread (light-weighted process) 跟process在實作上幾乎一樣. 最大的差異來自於,thread 會分享 virtual memory address s ...

  9. spring(六):spring中AOP的基本使用

    AOP:面向切面编程[底层使用动态代理实现],就是在运行期间动态的将某段代码切入到方法的指定位置进行运行的编程方式 基本使用 使用AOP功能需要引入spring的aop以及aspects相关包 < ...

  10. Java实现ArrayList

    说明都在注释: package adt.array; import java.util.Iterator; import java.util.NoSuchElementException; /** * ...