Codeforces 476C Dreamoon and Sums (水

题目链接:点击打开链接

题意:

给定a,b

对于一个数x。若x是nice number,则满足(x/b)/(x%b) == [1,a](即结果在1-a之间)

问:

输出一个数表示 全部nice number的和。

推一推公式就好。。

结果就是

b*(b-1)/2 * (a + b*( (1+a)*a/2 ) )

#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
template <class T>
inline bool rd(T &ret) {
    char c; int sgn;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?

0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template <class T> inline void pt(T x) { if (x <0) { putchar('-'); x = -x; } if(x>9) pt(x/10); putchar(x%10+'0'); } using namespace std; typedef long long ll; #define N 200010 const ll mod = 1000000007; ll a, b; int main() { while(cin>>a>>b){ ll ans = (a*(1+a))/2; ans %= mod; ans *= b; ans %= mod; ans += a; ans %= mod; ll B = b*(b-1)/2 % mod; ans *= B; ans %= mod; cout<<ans<<endl; } return 0; }



原文地址:https://www.cnblogs.com/claireyuancy/p/6747963.html