zoukankan      html  css  js  c++  java
  • cf(#div1 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 and y. 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 a, b (1 ≤ a, b ≤ 107).

    Output

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

    Sample test(s)
    Input
    1 1
    Output
    0
    Input
    2 2
    Output
    8
    Note

    For the first sample, there are no nice integers because is always zero.

    For the second sample, the set of nice integers is {3, 5}.

    题意:

          给你两个整数a,b ,定义这样一个数为漂亮数: 

        (1) x>0  ;  (2)x%b!=0 ;  (3)  (x/b)/(x%b)=k;  (4)k属于[1,a];

    求这样的漂亮数的所有之和。

        对于这样题,分析起来其实还是很简单的, 对于求和(sum),我们需要做的第一件事就是确定漂亮数的边界(上限和下限)、由于(3) (x/b)/(x%b)=k

    可以得出: x/b = k*(x%b);              x%b的剩余系即{1,2,3,4,5,......b-1}里的最大系;我们不放设定y={1,2,3,4,5,........b-1};

      不难得出:  x=k*y*b+y; -->x=(k*b+1)*y 所以可以推断公式:  x=Σ1a (k*b+1)*Σ1b-1 (y);

     进一步简化后部分: x=Σ1a (k*b+1)*(b-1)*(b)/2;

    所以代码为:

     1 #include<cstdio>
     2 #include<cstring>
     3 #define LL __int64
     4 #define mod 1000000007
     5 int main()
     6 {
     7   LL  a,b;
     8   LL sum;
     9   while(scanf("%I64d%I64d",&a,&b)!=EOF)
    10   {
    11         sum=0;
    12       for(LL j=1;j<=a;j++)
    13       {
    14           sum+=((j*b)%mod+1)%mod;
    15           sum%=mod;
    16       }
    17       LL ans=(((b-1)*b)/2)%mod;
    18      printf("%I64d
    ",(sum*ans)%mod);
    19   }
    20   return 0;
    21 }
    View Code
  • 相关阅读:
    MySQL表操作:字段类型 约束条件
    MySQL安装 sql语句
    O学堂作文
    iOS沙盒
    xcode 8带来的问题
    身份证号验证(省份,生日,末位校验)
    UIView的layoutSubviews和drawRect方法何时调用
    UIView超出父视图部分响应
    xcode 8带来的问题
    计算今天是周几
  • 原文地址:https://www.cnblogs.com/gongxijun/p/4025578.html
Copyright © 2011-2022 走看看