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 ...
随机推荐
- CSRF(跨站请求伪造)攻击方式
一.CSRF是什么? CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为:CSR ...
- WSDL相关文档
http://msdn.microsoft.com/en-us/library/ms996486.aspx http://msdn.microsoft.com/en-us/library/aa4685 ...
- jquery的show/hide性能测试
这篇文章是jQuery各种 show/hide方式的性能测试.作者之所以测试这个源于Robert Duffy在SanFrancisco举行的jQuery大会上的一句话:“.hide()和.show() ...
- 帝国cms无法注册登录快速解决方法 附路径
帝国cms安装相对比较简单,一路next,一般从网上下载的系统都会带一些数据,恢复备份数据后,清除缓存,更新数据,一个copy版的网站就出来了.但是为了se的友好需要改动很多地方,不然很容易被认为是s ...
- Sqli-labs less 19
Less-19 从源代码中我们可以看到我们获取到的是HTTP_REFERER 那和less18是基本一致的,我们从referer进行修改. 还是像less18一样,我们只给出一个示例 将referer ...
- pyhton Chapter3 读文件
使用内置函数open()打开文件,data=open("1.txt").利用data.close()关闭文件.利用data.readline()读取文件中的一行数据,然后指示读取文 ...
- POJ 2135
Farm Tour Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10840 Accepted: 4011 Descri ...
- ExtJs布局之tabPanel
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- hdu 4722 Good Numbers 数位DP
数位DP!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include< ...
- 知问前端——概述及jQuery UI
知问系统,是一个问答系统.主要功能:即会员提出问题,会员回答问题.目前比较热门的此类网站有:知乎http://www.zhihu.com.百度知道http://zhidao.baidu.com等.这里 ...