zoukankan      html  css  js  c++  java
  • Codeforces Round #272 (Div. 2) C. Dreamoon and Sums 数学

    C. Dreamoon and Sums

    题目连接:

    http://www.codeforces.com/contest/476/problem/C

    Description

    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 Input

    1 1

    Sample Output

    0

    Hint

    题意

    求有满足条件的数的和,条件是x/b / x%b = b,问你x有多少种可能的选择

    题解:

    把式子的分母移过去,然后就可以枚举了

    然后发现枚举实际上是可以O(1)计算的……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int mod = 1e9+7;
    long long a,b,x,y,sum;
    int main()
    {
        cin>>a>>b;
        x=(b*(b-1)/2)%mod;
        y=(a*(a+1)/2)%mod;
        sum=(x*((y*b)%mod+a)%mod)%mod;
        printf("%lld
    ",sum);
    }
  • 相关阅读:
    Synchronized和Lock的实现原理和锁升级
    如何禁止CPU指令重排
    MESI缓存一致性
    归并排序
    强软弱虚四种引用和ThreadLocal内存泄露
    VINS-Mono代码分析与总结(完整版)
    IMU误差模型与校准
    小感
    K8S conul部署
    Centos Consul集群及Acl配置
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5794623.html
Copyright © 2011-2022 走看看