CF 476 div2 C
http://www.codeforces.com/contest/476/problem/C
C. Dreamoon and Sums
1.5 seconds
256 megabytes
standard input
standard output
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if
and
, where k is some integer number in range[1, a].
By
we denote the quotient of integer division of x and y. By
we denote the remainder of integer division of x andy. 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 / b) / (x % b) = k(1 <= k <= a),问满足条件的x的总合
思路:我们得到x/b = k * (x%b),令x%b=i,然后枚举i即可得到相应的x = i * k * b + i,
然后即可得到暴力枚举的公式ans = ((1LL * i * ta % mod * b % mod + a * i % mod) % mod + ans) % mod,因此这种方法是O(b)的复杂度( 无语了,这里因为中间的mod爆了LL导致后来卡了一会儿,果然做事需要谨慎点。)
当然如果把i提取出来还可以用O(1)的方法计算。
//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
const int maxn = + ;
const LL mod = 1e9 + ;
LL a, b; int main(){
cin >> a >> b;
LL ans = ;
LL ta = (a + ) * a / % mod;
for (int i = ; i < b; i++){
ans = ((1LL * i * ta % mod * b % mod + a * i % mod) % mod + ans) % mod;
}
printf("%I64d\n", ans);
return ;
}
CF 476 div2 C的更多相关文章
- cf 442 div2 F. Ann and Books(莫队算法)
cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...
- CF#603 Div2
差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...
- CF R631 div2 1330 E Drazil Likes Heap
LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...
- CF#581 (div2)题解
CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...
- [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)
题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...
- CF 197 DIV2 Xenia and Bit Operations 线段树
线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...
- CF#345 div2 A\B\C题
A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...
- CF R303 div2 C. Woodcutters
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CF 192 Div2
A.Cakeminator 暴搞之,从没有草莓覆盖的行.列遍历 char map[30][30]; int vis[30][30]; int hang[30],lie[30]; int main() ...
随机推荐
- NodeJS 学习笔记一
他创造NodeJS的目的是为了实现高性能Web服务器,他首先看重的是事件机制和异步IO模型的优越性,而不是JS.但是他需要选择一种编程语言实现他的想法,这种编程语言不能自带IO功能,并且需要能良好支持 ...
- win7 xp 双系统安装记录
原机win7 64 增加xp x86 win7在c盘,xp装h盘 1.老毛桃pe,雨林木风gho,蓝屏,0000007b 2.通用pe.雨林木风gho,蓝屏,00000007b 3.pe设置h盘为系统 ...
- Minigui3.0 自定义遥控输入引擎
本人最近在从事minigui的开发工作,使用的gui版本为最新的3.0.12,平台环境为海思的HI3515. 在历经千辛万苦,终于将gui成功的移植到了开发板上,这里不多赘述,没有移植成功的朋友可以点 ...
- JPA基本注解介绍
一.@Entity •@Entity 标注用于实体类声明语句之前, 指出该Java 类为实体类,将映射到指定的数据库表. 如声明一个实体类 Customer,它将映射到数据库中的 customer 表 ...
- Windows API 之 GetModuleHandle
Retrieves a module handle for the specified module. The module must have been loaded by the calling ...
- Chapter 1 First Sight——36
The door opened again, and the cold wind suddenly gusted through the room, rustling the papers on th ...
- MySQL 出现 The table is full 的解决方法【转】
[MySQL FAQ]系列 — 你所不知的table is full那些事 时间 2014-08-21 12:18:56 MySQL中文网 原文 http://imysql.com/2014/08 ...
- 缩放系列(二):所有子控件也随着缩放、手势缩放、多点触控layout
下面是一个功能强大的改造的例子: 可以实现以下需求: 1.两个手指进行缩放布局 2.所有子控件也随着缩放, 3.子控件该有的功能不能丢失(像button有可被点击的功能,缩放后不能丢失该功能) 运行效 ...
- AOP与动态代理有什么联系
曾遇到“AOP与动态代理有什么联系”的问题,现把个人观点整理如下: 我觉得,动态代理是AOP的主要实现手段之一,AOP是动态代理的一种应用深化 AOP是一种思想,或者是方法论,类似OOP,是OOP的有 ...
- MVC(@html.action)调用子操作方法
1*简单调用 子操作方法: 服务端 客户端 2.带有参数的调用 子操作方法 服务端 客户端