Codeforces 476C Dreamoon and Sums【思维】
来源:互联网 发布:linux按时间分割log 编辑:程序博客网 时间:2024/05/22 06:38
Dreamoon loves summing up something for no reason. One day he obtains two integersa and b occasionally. He wants to calculate the sum of allnice integers. Positive integer x is called nice if and, wherek is some integer number in range [1, a].
By we denote thequotient 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?
The single line of the input contains two integers a,b (1 ≤ a, b ≤ 107).
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
1 1
0
2 2
8
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,让你找所有X,满足X/b/X%b==K,(1<=K<=a,X%b!=0)
思路:
1、
①考虑到x%b的值可能为1,2,3,4..........b-1。
②再考虑到X/B:
对应如果X%b的值为1,那么对应X/b的值可行有:1,2,3,4............a,那么对应X的值可行有:b+1,2b+1,3b+1,4b+1................a(b-1)+1.
对应如何X%b的值为2,那么对应X/b 的值可行有:2,4,6,8...........2a,那么对应X的值可行有:2b+1,4b+1,6b+1,8b+1...............2a(b-1)+1
.....................依次类推。
2、那么累加和就是:
【1<=i<b】output+=a*(1+a)/2*i*b+a*i;
3、注意取模姿势。
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;#define mod 1000000007#define ll __int64int main(){ ll a,b; while(~scanf("%I64d%I64d",&a,&b)) { ll output=0; for(ll i=1;i<b;i++) { output=(output+a*i)%mod; ll tmp=(1+a)*a/2%mod; tmp=i*tmp%mod; tmp=tmp*b%mod; output=(output+tmp)%mod; } printf("%I64d\n",output); }}
- Codeforces 476C Dreamoon and Sums【思维】
- Codeforces 476C. Dreamoon and Sums
- codeforces 476C Dreamoon and Sums
- Codeforces 476C Dreamoon and Sums (水
- codeforces 476c Dreamoon and Sums
- codeforces 476c Dreamoon and Sums
- Codeforces 476C Dreamoon and Sums
- Codeforces 476C Dreamoon and Sums
- Dreamoon and Sums CodeForces - 476C
- CF 476C Dreamoon and Sums[数学]
- Code Forces 476C Dreamoon and Sums
- 【CODEFORCES】 A. Dreamoon and Sums
- C. Dreamoon and Sums(Codeforces Round #272)
- 【Codeforces】 477A Dreamoon and Sums
- Codeforces Round #272 (Div. 2) C Dreamoon and Sums(数学)
- 【CODEFORCES】 C. Dreamoon and Strings
- Dreamoon and Sums 数学
- 477 A. Dreamoon and Sums
- unity day 4
- 原生的Ajax的封装
- I2C总线协议详解
- powermock实战教学
- Mybatis foreach嵌套遍历Map的key和value
- Codeforces 476C Dreamoon and Sums【思维】
- 最小路径
- 第92篇跳转关闭窗口开发(二)
- Spring与代理模式和实例工厂模式的整合使用
- SVM支持向量机-拉格朗日,对偶算法的初解
- 插入区间
- cJSON的使用方法
- Python进阶-类继承
- [openjudge] Ride to Office