cf(#div1 A. Dreamoon and Sums)(数论)
1.5 seconds
256 megabytes
standard input
standard output
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if
and
, where k is some integer number in range [1, a].
By
we denote the quotient of integer division of x and y. By
we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
1 1
0
2 2
8
For the first sample, there are no nice integers because
is always zero.
For the second sample, the set of nice integers is {3, 5}.
题意:
给你两个整数a,b ,定义这样一个数为漂亮数:
(1) x>0 ; (2)x%b!=0 ; (3) (x/b)/(x%b)=k; (4)k属于[1,a];
求这样的漂亮数的所有之和。
对于这样题,分析起来其实还是很简单的, 对于求和(sum),我们需要做的第一件事就是确定漂亮数的边界(上限和下限)、由于(3) (x/b)/(x%b)=k
可以得出: x/b = k*(x%b); x%b的剩余系即{1,2,3,4,5,......b-1}里的最大系;我们不放设定y={1,2,3,4,5,........b-1};
不难得出: x=k*y*b+y; -->x=(k*b+1)*y 所以可以推断公式: x=Σ1a (k*b+1)*Σ1b-1 (y);
进一步简化后部分: x=Σ1a (k*b+1)*(b-1)*(b)/2;
所以代码为:
#include<cstdio>
#include<cstring>
#define LL __int64
#define mod 1000000007
int main()
{
LL a,b;
LL sum;
while(scanf("%I64d%I64d",&a,&b)!=EOF)
{
sum=;
for(LL j=;j<=a;j++)
{
sum+=((j*b)%mod+)%mod;
sum%=mod;
}
LL ans=(((b-)*b)/)%mod;
printf("%I64d\n",(sum*ans)%mod);
}
return ;
}
cf(#div1 A. Dreamoon and Sums)(数论)的更多相关文章
- cf(#div1 B. Dreamoon and Sets)(数论)
B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 477A A. Dreamoon and Sums(数学)
题目链接: A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input ...
- 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】 A. Dreamoon and Sums
A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...
- CF 984C Finite or not? (数论)
CF 984C Finite or not? (数论) 给定T(T<=1e5)组数据,每组数据给出十进制表示下的整数p,q,b,求问p/q在b进制意义下是否是有限小数. 首先我们先把p/q约分一 ...
- 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. 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. 1) A. Dreamoon and Sums(数论)
题目链接 Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occa ...
- cf 450b 矩阵快速幂(数论取模 一大坑点啊)
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
随机推荐
- iOS内存管理编程指南
iOS 内存管理 目录[-] 一:基本原则 二:成员变量的内存管理 三:容器对象与内存管理 四:稀缺资源的管理 五:AutoRelease 六:其他注意事项 iOS下内存管理的基本思想就是引用计数,通 ...
- MySQL(六) —— 运算符和函数
1. 字符函数 函数名称 描述 CONCAT() 字符连接 CONCAT_WS() 使用指定的分隔符进行字 ...
- linux下vim命令详解
高级一些的编辑器,都会包含宏功能,vim当然不能缺少了,在vim中使用宏是非常方便的::qx 开始记录宏,并将结果存入寄存器xq 退出记录模式@x 播放记录在x寄存器中的宏命令 ...
- Servlet异常及其生命周期
Servlet 异常 在javax.servlet包中定义了两个异常类 ServletException类 ServletException类定义了一个通用的异常,可以被init().service( ...
- java运行期类型鉴定
运行期类型识别?RTTI? 假如我们有一个基类的引用,这个引用也可以作为子类的引用嘛,现在我们想知道这个引用的类型到底是啥? 当从子类到基类之后有很多的信息都会丢失掉,比如有一个人类的对象可以看成普遍 ...
- 6.Type and Member Basics
1.The Different Kinds of Type Members 1.Constants:a symbol that identifies a never-changing data val ...
- FZU 2214 Knapsack problem(背包问题)
Description 题目描述 Given a set of n items, each with a weight w[i] and a value v[i], determine a way t ...
- CSS笔记(四)文本
CSS 文本属性可定义文本的外观.通过文本属性,可以改变文本的颜色.字符间距,对齐文本,装饰文本和对文本进行缩进,等等. 参考:http://www.w3school.com.cn/css/css_t ...
- Iframe刷新父窗口的几种方式
/*Iframe刷新父窗口的几种方式在iframe的子页面中,使用onload刷新父页面的时候,遇到了一些问题. 1.目前来说,测试成功,并且兼容IE6/7和FF的刷新方式. */ <scrip ...
- hibernate对象关系实现(一)一对多
hibernate是对jdk一个封装工具,实现对象和数据库之间数据映射.使用时涉及到四个问题:a.对象之间的关系在类中的体现:b,对象关系对应的数据库中表之间体现:c.实现a,b在hibernate的 ...