zoukankan      html  css  js  c++  java
  • 湖南多校对抗赛---Jerry's trouble

    题目网址:http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2071&pid=9

    Description

     Jerry is caught by Tom. He was penned up in one room with a door, which only can be opened by its code. The code is the answer of the sum of the sequence of number written on the door. The type of the sequence of number is

    But Jerry’s mathematics is poor, help him to escape from the room.

    Input

     There are some cases (about 500). For each case, there are two integer numbers n, m describe as above ( 1 <= n < 1 000 000, 1 <= m < 1000).

    Output

     For each case, you program will output the answer of the sum of the sequence of number (mod 1e9+7).

    Sample Input

    4 1
    5 1
    4 2
    5 2
    4 3

    Sample Output

    10
    15
    30
    55
    100

    题意很简单,快速幂完全可以解决,直接贴码

    #include<iostream>
    #include <cmath>
    using namespace std; 
    long long int q=1e9+7 ;
    long long int ex(long long int a,long long int b){
           long long int ans;
            a=a%q;
            ans=1;
            while(b>0){
                if(b&1)//判断是否为奇数,相当于 if(b%2==1)
                    ans=(ans*a)%q;
                a=(a*a)%q;
                b=b>>1;//二进制向右移一位,相当于 b=b/2;
            }
        return ans;
    }
    int main()
    {
        long long int n,m;
        while(cin>>n>>m)
        {
            long long int sum=0;
            for(int i=1;i<=n;i++)
             sum=(sum+ex(i,m))%q;
              
        cout<<sum<<endl;
        }
        return 0;
    }
    




  • 相关阅读:
    查看日志
    MySQL连接方式和启动方式
    day03--MySQL用户篇
    MySQL5.6与5.7区别
    Ansible部署主从复制
    day03--MySQL多实例及多实例主从
    MySQL体系结构
    day02-mysql编译安装误删除用户恢复
    数据库包获取方式
    day01--数据库介绍及二进制安装MySQL5.6
  • 原文地址:https://www.cnblogs.com/zswbky/p/5431983.html
Copyright © 2011-2022 走看看