Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)
这个题取模的时候挺坑的!!!
题意:div(x , b) / mod(x , b) = k( 1 <= k <= a)。求x的和
分析:
我们知道mod(x % b)的取值范围为 1 - (b-1)。那么我们可以从这一点入口来进行解题。。
mod (x, b) = 1 时, x = b + 1, 2b + 1, 3b + 1..... a * b + 1.
mod (x , b) = 2 时, x = 2b + 2, 4b + 2, 6b + 2, ..... 2a * b + 2. = 2(b + 1), 2(2b + 1), 2(3b + 1)...... 2(a * b + 1).
....
mod (x , b) = b - 1..
可将等式化为:x=k*mod(x,b)*b+mod(x,b).
枚举1-b-1. 发现每一个式子都是等差数列 可得:ans += (a*(2*i+i*a*b+i*b))/2; 但是会发现 s a, b (1 ≤ a, b ≤ 107).
中间乘起来的时候会超LL, 而且这个式子要对除2, 其实ai*() 这两个乘数里至少有一个偶数,找到并除2就行了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <algorithm>
#define LL __int64
const int mo = 1e9+;
const int maxn = +;
using namespace std;
LL a, b; int main()
{
LL i;
LL ans;
while(~scanf("%I64d%I64d", &a, &b))
{
ans = ;
for(i = ; i < b; i++)
{
if((a*i)%==)
{
LL tmp = (a*i/)%mo;
ans += (((+a*b+b)%mo)*tmp)%mo;
ans %= mo;
}
else
{
LL tmp = ((+a*b+b)/)%mo;
ans += ((a*i%mo)*tmp)%mo;
ans %= mo;
}
}
printf("%I64d\n", ans);
}
return ;
}
Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)的更多相关文章
- Codeforces Round #272 (Div. 2)C. Dreamoon and Sums 数学推公式
C. Dreamoon and Sums Dreamoon loves summing up something for no reason. One day he obtains two int ...
- Codeforces Round #272 (Div. 2) C. Dreamoon and Sums 数学
C. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #272 (Div. 2)-C. Dreamoon and Sums
http://codeforces.com/contest/476/problem/C C. Dreamoon and Sums time limit per test 1.5 seconds mem ...
- Codeforces Round #272 (Div. 1) A. Dreamoon and Sums(数论)
题目链接 Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occa ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets (思维 数学 规律)
题目链接 题意: 1-m中,四个数凑成一组,满足任意2个数的gcd=k,求一个最小的m使得凑成n组解.并输出 分析: 直接粘一下两个很有意思的分析.. 分析1: 那我们就弄成每组数字都互质,然后全体乘 ...
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划
E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造
D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi dp
B. Dreamoon and WiFi 题目连接: http://www.codeforces.com/contest/476/problem/B Description Dreamoon is s ...
- Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题
A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...
随机推荐
- 15万甚至30万以内的SUV值不值得买?
大家好,这个帖子比较长,也是我一直以来长期实践.思考.验证的结论,不当之处还请指正,也欢迎大家来共 同讨论,已经买了此价位SUV的战友们,看完后也不要生气,毕竟我的出发点是注重行车安全,人非神明,是个 ...
- [百度空间] [原]CImageList支持32位透明位图
32位的位图主要是包含Alpha值(0-255)可以有半透效果的.之前用FreeImage加载 的DIB, CImageList直接绘制会有黑色背景.即便用了ILC_MASK,也创建了mask map ...
- Codeforces Round #204 (Div. 2)->C. Jeff and Rounding
C. Jeff and Rounding time limit per test 1 second memory limit per test 256 megabytes input standard ...
- HDU1056 HangOver
HangOver Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descript ...
- 7 linux服务器程序规范
1. Linux服务器程序一般以后台进程形式运行.后台进程又称守护进程(daemon),它没有控制终端,因而不会意外接收到用户输入.父进程通常为init(PID为1的进程)2. Linux服务器程序常 ...
- <context:annotation-config> 跟 <context:component-scan>诠释及区别
<context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注 ...
- ID3决策树---Java
1)熵与信息增益: 2)以下是实现代码: //import java.awt.color.ICC_ColorSpace; import java.io.*; import java.util.Arra ...
- 7 天玩转 ASP.NET MVC - 第 1 天
0. 前言 正如标题「7 天玩儿转 ASP.NET MVC」所言,这是个系列文章,所以将会向大家陆续推出 7 篇.设想一下,一天一篇,你将从一个愉快的周一开始阅读,然后在周末成为一个 ASP.NET ...
- POJ 2891 Strange Way to Express Integers (解一元线性方程组)
求解一元线性同余方程组: x=ri(mod ai) i=1,2,...,k 解一元线性同余方程组的一般步骤:先求出前两个的解,即:x=r1(mod a1) 1x=r2(mod a2) ...
- (转)Android之ListView原理学习与优化总结
转自: http://jishu.zol.com.cn/12893.html 在整理前几篇文章的时候有朋友提出写一下ListView的性能优化方面的东西,这个问题也是小马在面试过程中被别人问到的….. ...