ACM_X章求和(数学)

X章求和

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

X章最喜欢求和了,他一看到什么鬼就什么鬼都加起来。one day,他得到了2个数a,b。他定义一个整数x为shenmegui数,假如x%b!=0且(x/b)/(x%b)=k(刚好整除),k是一个整数,且k的范围为[1,a]。X章想把所有shenmegui数都加起来,求和。

Input:

输入包括一行,2个整数a,b(1<=a,b<=10^7)

Output:

输出占1行,一个整数,整数取余1000000007(10^9+7)
note:满足第二个样例的数为3和5,3+5=8

Sample Input:

1 1
2 2

Sample Output:

0
8
解题思路:推导+证明!!!
AC代码:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=1e9+7;
 5 inline void print(LL x){
 6     if(x<0)putchar('-'),x=-x;
 7     if(x>9)print(x/10);
 8     putchar(x%10+'0');
 9 }
10 LL a,b,ans;
11 int main(){
12     while(~scanf("%lld%lld",&a,&b)){
13         ans=(a*(1LL+a)/2%mod*b%mod+a)*(b*(b-1LL)/2%mod)%mod;///公式推导
14         print(ans),puts("");
15     }
16     return 0;
17 }
原文地址:https://www.cnblogs.com/acgoto/p/10047588.html