zoukankan      html  css  js  c++  java
  • 洛谷P1630 求和

    题目描述

    求1^b+2^b+……+a^b的和除以10000的余数。

    输入格式

    第一行包含一个正整数N,表示共有N组测试数据;

    接下来N行,每行包含两个正整数a和b。

    【数据规模】

    对于30%的数据中,满足N<=10,a,b<=1000;

    对于100%的数据中,满足N<=100,a,b<=1000000000;

    输出格式

    共N行,每行一个对应的答案。

    输入输出样例

    输入 #1
    1
    2 3
    输出 #1
    9

    思路:::我们只需对MOD10000的数据进行操作 ( a*b%MOD=a%MOD*b%MOD;)
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const ll MOD=10000;
    const int maxn=1e5+5;
    int quick(int x,int p)
    {
        int ans=1;
        while(p)
        {
            if(p&1){
                ans=ans*x%MOD;
            }
            x=x*x%MOD;
            p=p>>1;
        }
        return ans;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            int ant=0,y=a/MOD;
            a=a%MOD;
            for(int i=1;i<=MOD;i++)
            {
                if(i<=a)//说明之前有y+1个这样的数
                {
                    ant=(ant+(y+1)*quick(i,b))%MOD;
                }
                else{//说明前面只有y个这样的数
                    ant=(ant+y*quick(i,b))%MOD;
                }
            }
            printf("%d
    ",ant);
        }
        return 0;
    }
    纵使单枪匹马,也要勇闯天涯
  • 相关阅读:
    c# WInform 自定义导航布局
    c# 关于DataTable
    Sql Server 表结构相关
    C# winform 文件管理
    c# SqlBulkCopy实现批量从数据集中把数据导入到数据库中
    C# winform 动态操作webService
    c# Winform实现发送邮件
    C# 网络编程 TcpListener
    1122考试T2
    1121考试总结
  • 原文地址:https://www.cnblogs.com/sj-gank/p/11430585.html
Copyright © 2011-2022 走看看