sum of power

Think:

PS : 题目出处“浪潮杯”山东省第八届ACM大学生程序设计竞赛

题目要求 就是 计算 从1到n的m次幂运算的和, 同时注意mod取余运算;

Problem Description

Calculate mod (1000000000+7) for given n,m.
Input

Input contains two integers n,m(1≤n≤1000,0≤m≤10).
Output

Output the answer in a single line.
Example Input

10 0

Example Output

10

Hint
Author
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007;
long long int ans;
long long int sum;
long long int p(int a, int n)
  {
     ans = 1;
     for (int i = 0;i < n;i ++)
        {
          ans = ans * a;
          ans = ans % mod;
        }
        return ans;
  }
int main()
 {
    int n, m;
    scanf("%d %d", &n, &m);
         sum = 0;
          for (int i = 1;i <= n;i ++)
            {
               sum = sum + p(i, m);
               sum = sum % mod;
            }
         printf("%lld\n", sum);
 }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Kars is tired and resentful of the narrow mindset of his village since they are content with staying where they are and are not trying to become the perfect life form. Being a top-notch inventor, Kars wishes to enhance his body and become the perfect life form. Unfortunately, n of the villagers have become suspicious of his ideas. The i -th villager has a suspicion of ai on him. Individually each villager is scared of Kars, so they form into groups to be more powerful. The power of the group of villagers from l to r be defined as f(l,r) where f(l,r)=|al−al+1|+|al+1−al+2|+…+|ar−1−ar|. Here |x−y| is the absolute value of x−y . A group with only one villager has a power of 0 . Kars wants to break the villagers into exactly k contiguous subgroups so that the sum of their power is minimized. Formally, he must find k−1 positive integers 1≤r1<r2<…<rk−1<n such that f(1,r1)+f(r1+1,r2)+…+f(rk−1+1,n) is minimised. Help Kars in finding the minimum value of f(1,r1)+f(r1+1,r2)+…+f(rk−1+1,n) . Input The first line contains a single integer t (1≤t≤100) — the number of test cases. The description of test cases follows. The first line of each test case contains two integers n,k (1≤k≤n≤100) — the number of villagers and the number of groups they must be split into. The second line of each test case contains n integers a1,a2,…,an (1≤ai≤500) — the suspicion of each of the villagers. Output For each test case, output a single integer — the minimum possible value of sum of power of all the groups i. e. the minimum possible value of f(1,r1)+f(r1+1,r2)+…+f(rk−1+1,n) . Example inputCopy 3 4 2 1 3 5 2 6 3 1 9 12 4 7 2 12 8 1 9 8 2 3 3 1 8 7 7 9 2 outputCopy 4 11 2 Note In the first test case, we will group the villagers with suspicion (1,3,5,2) into (1,3,5) and (2) . So, f(1,3)+f(4,4)=(|1−3|+|3−5|)+0=4+0=4 . In the second test case, we will group the villagers with suspicion (1,9,12,4,7,2) into (1),(9,12),(4,7,2) . So, f(1,1)+f(2,3)+f(4,6)=0+3+8=11 .
07-07

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值