A Simple But Difficult Problem

Time Limit: 5000ms
Memory Limit: 65536KB

64-bit integer IO format: %lld      Java class name: Main

Type:

None

 

None
 
Graph Theory
 
    2-SAT
 
    Articulation/Bridge/Biconnected Component
 
    Cycles/Topological Sorting/Strongly Connected Component
 
    Shortest Path
 
        Bellman Ford
 
        Dijkstra/Floyd Warshall
 
    Euler Trail/Circuit
 
    Heavy-Light Decomposition
 
    Minimum Spanning Tree
 
    Stable Marriage Problem
 
    Trees
 
    Directed Minimum Spanning Tree
 
    Flow/Matching
 
        Graph Matching
 
            Bipartite Matching
 
            Hopcroft–Karp Bipartite Matching
 
            Weighted Bipartite Matching/Hungarian Algorithm
 
        Flow
 
            Max Flow/Min Cut
 
            Min Cost Max Flow
 
DFS-like
 
    Backtracking with Pruning/Branch and Bound
 
    Basic Recursion
 
    IDA* Search
 
    Parsing/Grammar
 
    Breadth First Search/Depth First Search
 
    Advanced Search Techniques
 
        Binary Search/Bisection
 
        Ternary Search
 
Geometry
 
    Basic Geometry
 
    Computational Geometry
 
    Convex Hull
 
    Pick's Theorem
 
Game Theory
 
    Green Hackenbush/Colon Principle/Fusion Principle
 
    Nim
 
    Sprague-Grundy Number
 
Matrix
 
    Gaussian Elimination
 
    Matrix Exponentiation
 
Data Structures
 
    Basic Data Structures
 
    Binary Indexed Tree
 
    Binary Search Tree
 
    Hashing
 
    Orthogonal Range Search
 
    Range Minimum Query/Lowest Common Ancestor
 
    Segment Tree/Interval Tree
 
    Trie Tree
 
    Sorting
 
    Disjoint Set
 
String
 
    Aho Corasick
 
    Knuth-Morris-Pratt
 
    Suffix Array/Suffix Tree
 
Math
 
    Basic Math
 
    Big Integer Arithmetic
 
    Number Theory
 
        Chinese Remainder Theorem
 
        Extended Euclid
 
        Inclusion/Exclusion
 
        Modular Arithmetic
 
    Combinatorics
 
        Group Theory/Burnside's lemma
 
        Counting
 
    Probability/Expected Value
 
Others
 
    Tricky
 
    Hardest
 
    Unusual
 
    Brute Force
 
    Implementation
 
    Constructive Algorithms
 
    Two Pointer
 
    Bitmask
 
    Beginner
 
    Discrete Logarithm/Shank's Baby-step Giant-step Algorithm
 
    Greedy
 
    Divide and Conquer
 
Dynamic Programming
                  Tag it!

计算前n个正整数的k次幂之和:

结果可能会非常非常大,输出结果的最后5位即可。
 

Input

输入数据有多组。每组数据一行,每行包括两个整数nk (1<=n<=1,000,000,000,1<=k<=1000)。
输入数据以-1 -1 结束。
 

Output

对每一组输入数据,输出单独一行,包括一个整数,给出对应的答案。
 

Sample Input

100 1
100 2
-1 -1

Sample Output

05050
38350

Source

 
 
解题思路:快速幂解决超时问题。
 
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<queue>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
#define mid (L+R)/2
#define lson rt*2,L,mid
#define rson rt*2+1,mid+1,R
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 300;
const int mod = 1e5;
LL qpowmod(LL n,LL k){
LL ret = 1;
while(k){
if(k&1)
ret = (ret*n) % mod;
k = k>>1;
n = n*n % mod;
}
return ret;
}
int main(){
LL n, k;
while(scanf("%lld%lld",&n,&k)!=EOF){
if(n==-1 && k==-1) break;
LL sum = 0;
LL mo = n%mod, quotient = n/mod;
if(quotient){
for(LL i = 1;i <= mod; i++){
sum = (sum + qpowmod(i,k)) % mod;
}
sum = (sum*quotient) % mod;
}
for(LL i = 1; i <= mo; i++){
sum = (sum + qpowmod(i,k))%mod;
}
printf("%05lld\n",sum);
}
return 0;
}

  

BNU 4356 ——A Simple But Difficult Problem——————【快速幂、模运算】的更多相关文章

  1. codeforces magic five --快速幂模

    题目链接:http://codeforces.com/contest/327/problem/C 首先先算出一个周期里面的值,保存在ans里面,就是平常的快速幂模m做法. 然后要计算一个公式,比如有k ...

  2. hdu 2462(欧拉定理+高精度快速幂模)

    The Luckiest number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  3. 2014多校第一场 I 题 || HDU 4869 Turn the pokers(费马小定理+快速幂模)

    题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少 ...

  4. 快速幂模n运算

    模运算里的求幂运算,比如 5^596 mod 1234, 当然,直接使用暴力循环也未尝不可,在书上看到一个快速模幂算法 大概思路是,a^b mod n ,先将b转换成二进制,然后从最高位开始(最高位一 ...

  5. URAL 1141. RSA Attack(欧拉定理+扩展欧几里得+快速幂模)

    题目链接 题意 : 给你n,e,c,并且知道me ≡ c (mod n),而且n = p*q,pq都为素数. 思路 : 这道题的确与题目名字很相符,是个RSA算法,目前地球上最重要的加密算法.RSA算 ...

  6. ACM学习历程—HDU5490 Simple Matrix (数学 && 逆元 && 快速幂) (2015合肥网赛07)

    Problem Description As we know, sequence in the form of an=a1+(n−1)d is called arithmetic progressio ...

  7. hdu 1757 A Simple Math Problem_矩阵快速幂

    题意:略 简单的矩阵快速幂就行了 #include <iostream> #include <cstdio> #include <cstring> using na ...

  8. E题:Water Problem(快速幂模板)

    题目大意:原题链接  题解链接 解题思路:令x=x-1代入原等式得到新的等式,两式相加,将sin()部分抵消掉,得到只含有f(x)的状态转移方程f(x+1)=f(x)+f(x-2)+f(x-3),然后 ...

  9. hdu-1757 A Simple Math Problem---矩阵快速幂模板题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1757 题目大意: 求递推式第k项模m If x < 10 f(x) = x.If x > ...

随机推荐

  1. mvc - codefirst 数据迁移

    from :http://blog.csdn.net/xiaoyiyz/article/details/41485325

  2. vs2015+opencv3.3.1 +Eigen 3.3.4 c++ 实现 泊松图像编辑(无缝融合)

    #define EIGEN_USE_MKL_ALL #define EIGEN_VECTORIZE_SSE4_2 #include <iostream> #include "co ...

  3. April Fools Day Contest 2019 A. Thanos Sort

    A. Thanos Sort time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. MVC进阶篇(四)——[HttpGet]和[HttpPost]

    前言 Get和post,一个获取请求,一个提交请求,在MVC里面用法也很特别,总结一下,我理解的不是特别深刻,希望多多交流. 内容 [HttpGet] 需求: 用户想要通过点击修改按钮来达到修改这部分 ...

  5. uoj #298. 【CTSC2017】网络

    #298. [CTSC2017]网络 一个一般的网络系统可以被描述成一张无向连通图.图上的每个节点为一个服务器,连接服务器与服务器的数据线则看作图上的一条边,边权为该数据线的长度.两个服务器之间的通讯 ...

  6. Python登陆人人网

    #!coding:utf-8 import urllib2 import urllib import cookielib def renrenBrower(url,user,password): #登 ...

  7. 手机端file限制只能选择图片、视频、音频,直接打开摄像头拍照或录像

    限制只能选择图片 <input type="file" accept="image/*"> 限制只能选择视频 <input type=&quo ...

  8. 关于执行webdriver.Chrome; 报错WebDriverException: Message: unknown error: Element is not clickable at point (1085, 103)

    from selenium import webdriverfrom time import sleep dr = webdriver.Chrome() dr.get("http://pj1 ...

  9. ansible基本模块-cron

    ansible   XXX   -m   cron   -a   "name=‘XXX ’   job=‘执行的命令’   minute=XXX "                ...

  10. redis原理及实现

    1 什么是redis redis是nosql(也是个巨大的map) 单线程,但是可处理1秒10w的并发(数据都在内存中) 使用java对redis进行操作类似jdbc接口标准对mysql,有各类实现他 ...