【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) = ...
随机推荐
- Permutations II 典型去重
https://leetcode.com/problems/permutations-ii/ Given a collection of numbers that might contain dupl ...
- KeepAlived的配置
KeepAlived的相关配置 KeepAlived 配置 参考帮助 man keepalived.conf 配置文件组件部分: top hierachy(层次) global configurati ...
- sql语句如何查询当天,一周,一月的数据的语句
sql查询当天,一周,一个月数据的语句 --查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: ...
- UVaLive 6834 Shopping (贪心)
题意:给定 n 个商店,然后有 m个限制,去 c 之前必须先去d,问你从0到n+1,最短路程是多少. 析:我们我们要到c,必须要先到d,那么举个例子,2 5, 3 7,如果我们先到5再到2,再到7再到 ...
- bzoj 1653: [Usaco2006 Feb]Backward Digit Sums【dfs】
每个ai在最后sum中的值是本身值乘上组合数,按这个dfs一下即可 #include<iostream> #include<cstdio> using namespace st ...
- JS中定时器的返回数值ID值
定时器会返回一个数字值id,可以由clearInterval(id)或clearTimeout(id)来实现对对应定时器的清除. setInterval()/setTimeout()BOM中的Wind ...
- C#结构体+结构体与类的区别
C# 结构(Struct) 在 C# 中,结构是值类型数据结构.它使得一个单一变量可以存储各种数据类型的相关数据.struct 关键字用于创建结构. C# 结构的特点 您已经用了一个简单的名为 Boo ...
- 全面学习ORACLE Scheduler特性(4)创建和管理Schedule
三.使用Schedules 10g 中新推出的SCHEDULER可能确实会让很多初接触的朋友感觉晕头晕脑,相比之前的jobs,SCHEDULER中新增的概念太多.比如说jobs,仍然可以理解成之前版本 ...
- TensorFlow OOM when allocating tensor with shape[5000,384707]
在session范围内不要进行eval()或者convert_to_tensor()操作, 否则会造成OOM,或者报出错误:GraphDef cannot be larger than 2GB usi ...
- servlet——web应用中路径问题
target.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html ...