1153 -- p次方求和
来源:互联网 发布:泽诺尼亚s下载最新数据 编辑:程序博客网 时间:2024/05/18 00:02
p次方求和
Time Limit:1000MS Memory Limit:65536K
Total Submit:200 Accepted:47
Description
一个很简单的问题,求1^p+2^p+3^p+……+n^p的和。
Input
第一行单独一个数字t表示测试数据组数。接下来会有t行数字,每行包括两个数字n,p,
输入保证0< n< =1000,0< =p< =1000。
Output
输出1^p+2^p+3^p+……+n^p对10003取余的结果,每个结果单独占一行。
Sample Input
210 110 2
Sample Output
55385
Source
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AK1153 { class Program { static int erfen(int n, int p) { int a = n; int b = p; int result = 1; while (b != 0) { if (b % 2 == 1) { result = (result * a) % 10003; //乘一个a,也就是i } a = (a * a) % 10003; //平方 b /= 2; //把这个数截一半 } return result; } static void Main(string[] args) { int t = int.Parse(Console.ReadLine()); while (t-- > 0) { string[] sb = Console.ReadLine().Split(); int n = int.Parse(sb[0]), p = int.Parse(sb[1]); int sum = 0; for (int i = 1; i <= n; i++) sum = (sum + erfen(i, p)) % 10003; Console.WriteLine(sum); } } } }
0 0
- 1153 -- p次方求和
- akoj-1153-p次方求和
- akoj-1153-p次方求和
- p次方求和
- nyoj420 p次方求和
- acm-p次方求和
- NYOJ p次方求和
- 420 p次方求和
- NYOJ-p次方求和
- p次方求和
- p次方求和
- p次方求和
- p次方求和
- NYOJ 420 p次方求和
- NYOJ-420:p次方求和
- NYOJ 420 p次方求和
- nyoj-420-p次方求和
- nyoj 420-p次方求和
- 1152 -- 整除个数
- 伸展树的删除例程
- [推荐]Rolling cURL: PHP并发最佳实践 商品价格监控 curl_multi族 函数
- hql关联表、map/list查询
- 车型识别“A Large-Scale Car Dataset for Fine-Grained Categorization and Verification”
- 1153 -- p次方求和
- HTML5 webSQL动态查询前端数据库表
- Mac系统常见的指令
- Codevs 题目1690 开关灯(线段树区间异或)
- Java 动态代理源码分析
- view 里面添加button,button没有反应
- 1154 -- 算菜价
- iOS7 textFeild的palcehole字号设置
- 女人怎么做好P2P理财?