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;
    }
    

      

  • 相关阅读:
    JavaBean 之Hello World(入门实例)
    Velocity之Hello World(入门实例)
    URL, URI 和 URN 之间的区别
    Windows平台的Windbg/x64dbg/OllyDbg调试器简介以及符号文件*.pdb总结(★firecat推荐★)
    VC++内存泄漏检测方法(5):使用强大的Windbg工具,重点是Symbols Path设置
    安装与配置windbg 的符号文件(转自一片文章的回复,回复者RegKiller)
    WinDbg下载符号文件(内核层、用户层)
    Windbg下载微软符号表
    windbg符号表问题
    WinDBG加载符号表的一点心得体会
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5848559.html
Copyright © 2011-2022 走看看