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 ...
随机推荐
- Devexpress TreeList选择父级联动
Treelist当显示复选框后,父级和子级的复选框没有关联,使用过程中很不便,如图所示 自己给treelist添加父子级联动 /// <summary> /// 初始化TreeList,父 ...
- Mysql错误问题记录
① Incorrect string value: '\xE6\x94\xBE\xE5\xA4\xA7...' for column 'name' at row 1 Query…… 原因:编码不匹配. ...
- 【转+自己研究】新姿势之Docker Remote API未授权访问漏洞分析和利用
0x00 概述 最近提交了一些关于 docker remote api 未授权访问导致代码泄露.获取服务器root权限的漏洞,造成的影响都比较严重,比如 新姿势之获取果壳全站代码和多台机器root权限 ...
- jenkins远程命令执行利用工具
昨天看小飞侠写的py的jenkins的脚本,昨天晚上在微信里评论今天写一个JAVA的GUI的tools. 早上花了点时间写一下: code: package com.tools; import jav ...
- C# WPF MVVM 实战 – 5- 用绑定,通过 VM 设置 View 的控件焦点
本文介绍在 MVVM 中,如何用 ViewModel 控制焦点. 这焦点设置个东西嘛,有些争论.就是到底要不要用 ViewModel 来控制视图的键盘输入焦点.这里不讨论,假设你就是要通过 VM,设置 ...
- 线程入门之优先级priority
package com.thread; /** * 优先级: * Thread.MAX_PRIORITY:最大优先级 10 * Thread.MIN_PRIORITY:最小优先级 1 * Thread ...
- Get started with Gazebo in ROS
Run Gazebo These three steps will run Gazebo with a default world. Install Gazebo. Open a terminal. ...
- STL--stack
stack--概述: 栈(Stack)是一种特殊的线性表,只能在某一端插入和删除的特殊线性表.它按照后进先出的原则存储数据,先进入的数据被压入栈底,最后的数据在栈顶.栈也称为先进后出表(LIFO). ...
- FLASH CC 2015 CANVAS 导出音频问题
1,导入音频无法成功发布(软件假死) 解决办法:先用个格式工厂重新压缩 在导入软件 发布 2, 音频 长度小于1秒(左右)的时候,导出后音频会变成 “哧”的一声, 估计和FLASH软件内部的音频编 ...
- 关于Spring定时任务(定时器)用法
Spring定时任务的几种实现 Spring定时任务的几种实现 一.分类 从实现的技术上来分类,目前主要有三种技术(或者说有三种产品): 从作业类的继承方式来讲,可以分为两类: 从任务调度的触发时机来 ...