题目链接

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

题意: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. [工作积累] Android dynamic library & JNI_OnLoad

    Bionic libc doesn't load dependencies for current .so file (diff from Windows or Linux) so a explici ...

  2. [转载]Thread.Sleep(0)妙用

    原文地址:http://blog.csdn.net/lgstudyvc/article/details/9337063 来自本论坛: 我们可能经常会用到 Thread.Sleep 函数来使线程挂起一段 ...

  3. Codeforces Round #263 (Div. 2)

    吐槽:一辈子要在DIV 2混了. A,B,C都是简单题,看AC人数就知道了. A:如果我们定义数组为N*N的话就不用考虑边界了 #include<iostream> #include &l ...

  4. ASP.NET输出PNG图片时出现GDI+一般性错误的解决方法

    偶原来的用ASP.NET生成验证码图片时用的是JPG格式,今天想把它改成PNG格式的,结果就出现GDI+一般性错误,查了N久资料,才发现解决的办法,对分享此解决办法的网友深表感谢 Response.C ...

  5. javascript document.write

    在载人页面后,浏览器输出流自动关闭:在此之后,任何一个对当前页面进行操作的document.write()方法将打开—个新的输出流.它将清除当前页面内容(包括源文档的任何变量或值).document. ...

  6. jQuery1.9.1--结构及$方法的工作原理源码分析

    jQuery的$方法使用起来非常的多样式,接口实在太灵活了,有点违反设计模式的原则职责单一.但是用户却非常喜欢这种方式,因为不用记那么多名称,我只要记住一个$就可以实现许多功能,这个$简直就像个万能的 ...

  7. C# 使用 AutoResetEvent 或 ManualResetEvent 同步两个线程

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. 几种CPU架构

    原文链接:http://blog.csdn.net/wyzxg/article/details/5027738 这几天在下载RPM包的时候,总会看见x86,x86-64,IA64,i386,i586等 ...

  9. CXF+Spring 搭建的WebService

    1.创建类 2.接口编写 package com.fan; import javax.jws.WebService; @WebService public interface IHelloWorld ...

  10. (9)nehe教程3--添加颜色

    添加颜色: 作为第二课的扩展,我将叫你如何使用颜色.你将理解两种着色模式,在左图中,三角形用的是光滑着色,四边形用的是平面着色. 上一课中我教给您三角形和四边形的绘制方法.这一课我将教您给三角形和四边 ...