【Codeforces 476C】Dreamoon and Sums
【链接】 我是链接,点我呀:)
【题意】
让你求出所有x的和
其中
(x div b)是(x mod b)的倍数
且x mod b不等于0
且(x div b)除(x mod b)的值(假设为k),k∈[1..a]
【题解】
枚举k从1~a
这样k就固定了
n = x / b;
m = x % b;
n = m*k ····①
x = b*n + m
x = (b*k+1)*m
而m∈[1..b-1]
所以求和一下就是∑x = (b*k+1)*( b*(b-1)/2)
这里我们m属于1..b-1,显然由①式可知,k不同的时候,m从1到b-1变化的话,
得到的n也是不同的.(因此每一组(n,m)都不会相同)
所以如果我们枚举不同的k值,然后m从1到b-1变化不会得到重复的x值的,因为每一个x值
都唯一标识了一组(n,m),而(n,m)不会重复
枚举k加起来就好啦
【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = 50000;
static class Task{
/*
* n = x / b;
* m = x % b;
* n = m*k
* x = b*n + m
* x = (b*k+1)*m
* m 1..b-1
* ∑x = (b*k+1)*( b*(b-1)/2)
* k 1..a
*/
long a,b;
long MOD = (int)(1e9+7),ans = 0;
public void solve(InputReader in,PrintWriter out) {
a = in.nextInt();b = in.nextInt();
for (long k = 1;k <= a;k++) {
long temp = (b*k+1)%MOD;
long temp1 = b*(b-1)/2%MOD;
temp = temp*temp1%MOD;
ans = (ans+temp)%MOD;
}
out.println(ans);
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
【Codeforces 476C】Dreamoon and Sums的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 509C】Sums of Digits
[题目链接]:http://codeforces.com/contest/509/problem/C [题意] 给你一个数组b[i] 要求一个严格升序的数组a[i]; 使得a[i]是b[i]各个位上的 ...
- 【63.73%】【codeforces 560A】Currency System in Geraldion
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- 采用jq链(end方法和andSelf()方法)
end()方法: <style type="text/css"> .m1{background:#09C;} .m2{border:1px solid #000;} & ...
- 我的周记2——“天道酬勤"
Get 什么是JAVA https://zhuanlan.zhihu.com/p/62717204 了解下HTTP 缓存机制 https://juejin.im/post/5a1d4e546fb9a ...
- $CF19A\ World\ Football\ Cup$
炒鸡\(6\)批的模拟题. 注意的是输入 把握好空格 大小写. 根据题目的这句话来排序 积分榜是按照以下原则制作的:胜利一个队得3分,平分1分,失败0分. 首先,球队按积分顺序排在积分榜上,分数相等比 ...
- c++ memset函数
函数名称:memset 函数所需头文件:#include<cstring> 函数作用:内存赋值函数,用来给某一块内存空间进行赋值的. 函数结构:memset(变量,一个数字,一个数字) ...
- C# 的占位符
static void Main(string[] args) { Console.WriteLine("A:{0},a:{1}",65,97); Console.ReadLine ...
- BFS(两点搜索) FZOJ 2150 Fire Game
题目传送门 题意:'#'表示草地,两个人在草地上点火,相邻的草地会烧起来,每烧一格等1秒,问最少要等几秒草地才烧完 分析:这题和UVA 11624 Fire!有点像,那题给定了两个点,这题两点不确定, ...
- java 分解整数 【个 十 百】(数组案例)
求一个数两位数的个位数,十位数,百位数及千位: int num = 53; int g = (num / 1) % 10; //个位 int s = (num / 10) % 10; //十位 in ...
- 2017-12-04HTML table布局
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- css的新特性 calc () 使用
calc()对大家来说,或许很陌生,不太会相信calc()是css中的部分.因为看其外表像个函数,既然是函数为何又出现在CSS中呢?这一点也让我百思不得其解,今天有一同事告诉我,说CSS3中有一个属性 ...
- js中取整数的方法
1.取整的方法 Math.floor( ) Math 对象的方法--取比当前数值小的最大整数(下取整). Math.ceil( ) Math对象的方法--取比当前数值大的最小整数(上取整). Math ...