zoukankan      html  css  js  c++  java
  • codeforces 477A A. Dreamoon and Sums(数学)

    题目链接:

    A. Dreamoon and Sums

    time limit per test
    1.5 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if  and , where k is some integer number in range[1, a].

    By  we denote the quotient of integer division of x and y. By  we denote the remainder of integer division of x andy. You can read more about these operations here: http://goo.gl/AcsXhT.

    The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?

    Input

    The single line of the input contains two integers ab (1 ≤ a, b ≤ 107).

    Output

    Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).

    Examples
    input
    1 1
    output
    0
    input
    2 2
    output
    8

    题意:

    计算满足上述要求的数的和,满足要求的数x/b是x%b的k倍,k属于[1,a];

    思路:

    一个推公式的题,x=b*div+mod;其中div=k*mod;所以x=(b*k+1)*mod;而1<=k<=a;1<=mod<=b-1;
    得到公式∑∑(b*k+1)*mod=(∑(b*k+1))*(∑mod)=b*(b-1)/2*(a+a*(a+1)/2*b);
    就变成水题了;

    AC代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
    #include <map>
      
    using namespace std;
      
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
      
    typedef  long long LL;
      
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
      
    const int mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=1e9;
    const int N=1e6+20;
    const int maxn=1e3+110;
    const double eps=1e-12;
     
    
    int main()
    {
        LL a,b;
        read(a);read(b);
        LL ans=b*(b-1)/2%mod;
        ans=ans*(a+a*(a+1)/2%mod*b%mod)%mod;
        cout<<ans<<endl;
        
        return 0;
    }
    

      

  • 相关阅读:
    c++中的数据类型
    C语言堆栈入门——堆和栈的区别
    用(*.frm *.MYD *.MYI)文件恢复MySql数据库
    GridView总结二:GridView自带编辑删除更新
    GridView总结一:GridView自带分页及与DropDownList结合使用
    对自己寒假的安排
    Python3 File
    Python3输入输出
    Python模块
    Python3数据结构
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5848559.html
Copyright © 2011-2022 走看看