题目链接

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

题意: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. Lessons learned from manually classifying CIFAR-10

    Lessons learned from manually classifying CIFAR-10 Apr 27, 2011 CIFAR-10 Note, this post is from 201 ...

  2. DreamFactory service platform 将DB发布成restful service

    PPT:http://www.slideshare.net/DreamFactorySoftware/angularjs-and-rest-made-simple blog:http://blog.d ...

  3. D3D Deferred Shading

    在3D图形计算中,deferred shading是一个基于屏幕空间的着色技术.之所以被称为deferred shading,是因为我们将场景的光照计算与渲染"deferred"到 ...

  4. Ruby Profiler 详解之 ruby-prof(I)

    项目地址: ruby-prof 在上一篇 Ruby 中的 Profiling 工具中,我们列举了几种最常用的 Profiler,不过只是简单介绍,这一次详细介绍一下 ruby-prof 的使用方法. ...

  5. POJ3469 Dual Core CPU(最小割)

    题意:给你n个模块,每个模块在A核花费为ai,在B核跑花费为bi,然后由m个任务(ai,bi,wi),表示如果ai,bi不在同一个核上跑,额外的花费为wi,求最小的花费. 一开始想的时候以为是费用流, ...

  6. 2015年4月 非常干货之Python资源大全

    [非常干货之Python资源大全]Python是一门美妙的语言,简单易用,容易提升.它是一门主流语言,却没有其它专业语言的弊病,从游戏,ML,GUI到科学和数学有着巨量的函数库. 直击现场 <H ...

  7. VMware 进入bios

    在虚拟机创建目录中找到.vmx结尾的文件. 添加bios.forceSetupOnce = "TRUE". 打开虚拟机,他会自动进入bios,随后他会把bios.forceSetu ...

  8. 【转】VC++与MySQL数据库的连接

    原文地址:http://blog.csdn.net/nupt123456789/article/details/8043091 1.MySQL数据库的安装 你可以从MySQL的官网上或者从如下地址下载 ...

  9. Project Euler 104:Pandigital Fibonacci ends 两端为全数字的斐波那契数

    Pandigital Fibonacci ends The Fibonacci sequence is defined by the recurrence relation: F[n] = F[n-1 ...

  10. c# 委托 和 事件

    当初学C#的时候,没有完全吃透的,只能现在继续了...  欠老账.... http://www.cnblogs.com/chengxingliang/archive/2013/05/21/305191 ...