题目链接

这个题取模的时候挺坑的!!!

题意: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 ab (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 (数学 思维)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #272 (Div. 2) D. Dreamoon and Sets (思维 数学 规律)

    题目链接 题意: 1-m中,四个数凑成一组,满足任意2个数的gcd=k,求一个最小的m使得凑成n组解.并输出 分析: 直接粘一下两个很有意思的分析.. 分析1: 那我们就弄成每组数字都互质,然后全体乘 ...

  6. Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划

    E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...

  7. Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造

    D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...

  8. 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 ...

  9. Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题

    A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...

随机推荐

  1. IE8下兼容rgba颜色的半透明背景

    在工作中做一个图片半透明遮罩时发现在IE8下不兼容 一查再知道IE8不支持rgba颜色,再搜搜兼容性方法,没想到这么快就解决了. 先说说rgba的含义: r代表red,g代表green,b代表blue ...

  2. IE8下jQuery改变png图片透明度时出现的黑边问题

    png24格式的图片在用jQuery添加显示隐藏动画时发现,图片的半透明区域出现黑边? 在网上搜了搜主要有以下几种办法: 1.把图片保存成PNG-8格式. 2.把背景色一起切入并保存为JPG格式. 以 ...

  3. PHPStorm+PHP5.6+WIN7+IIS7

    文件下载 以下为参考网址,如无法打开或变动,请自行搜索,获取最新版本文件请行搜索 PHP Manager:http://www.iis.net/downloads/community/2010/09/ ...

  4. Java检查型异常和非检查型异常

    1.代码 public class ExcepTest { /** * @param args */ public static void main(String[] args) { System.e ...

  5. SELINUX设为Disable 影响java SSH工具包Jsch 0.1.49.jar的一个案例

    最近项目中遇到一个典型事件,当RHEL 的SELINUX设为DISABLE时 使用JAVA的Jsch 库调用SSH命令时将随机返回空字符串,我使用的版本是0.1.49,最新版本0.1.51未测试. 关 ...

  6. Javascript Arguments,calle,caller,call,apply

    一.Arguments 该对象代表正在执行的函数和调用他的函数的参数. [function.]arguments[n] 参数function :选项.当前正在执行的 Function 对象的名字. n ...

  7. TCP/IP协议 三次握手与四次挥手【转】

    一.TCP报文格式 TCP/IP协议的详细信息参看<TCP/IP协议详解>三卷本.下面是TCP报文格式图: 图1 TCP报文格式 上图中有几个字段需要重点介绍下:        (1)序号 ...

  8. NTP服务及时间同步(CentOS6.x)

    博客分类: linux   今有一小型项目,完全自主弄,原来以为很简单的NTP服务,我给折腾了2个多小时才整撑头(以前都是运维搞,没太注意,所以这技术的东西,在简单都需要亲尝啊),这里记录为以后别再浪 ...

  9. 关于yum仓库的中的软件包下载

    在Linux系统下,很多软件的安装我们都会选择使用yum的方式安装,因为简单方便,易于管理. 有时我们可能会有这样的一个需求:即喜欢上yum仓库中的一个软件了,想要下载到本地.该怎么办呢? 实现方法不 ...

  10. SpringMVC深入探究(1)——DispatcherServlet与初始化主线

    在上一篇文章中,我们给出了构成SpringMVC应用程序的三要素以及三要素的设计过程.让我们来归纳一下整个设计过程中的一些要点: SpringMVC将Http处理流程抽象为一个又一个处理单元 Spri ...