博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 2620 Ice Rain 余数的性质
阅读量:3904 次
发布时间:2019-05-23

本文共 1565 字,大约阅读时间需要 5 分钟。

Problem Description

Ice Rain------I was waiting for a girl, or waiting for been addicted to the bitter sea. Love for irrigation in silence. No one considered whether the flowers came out or wither. Love which I am not sure swing left and right. I had no choice but to put my sadness into my heart deeply.

   Yifenfei was waiting for a girl come out, but never.
His love is caught by Lemon Demon. So yifenfei ’s heart is “Da Xue Fen Fei” like his name.
The weather is cold. Ice as quickly as rain dropped. Lemon said to yifenfei, if he can solve his problem which is to calculate the value of , he will release his love.
Unluckily, yifenfei was bored with Number Theory problem, now you, with intelligent, please help him to find yifenfei’s First Love.

 

 

Input

Given two integers n, k(1 <= n, k <= 109).

 

 

Output

For each n and k, print Ice(n, k) in a single line.

 

 

Sample Input

 

5 4

5 3

 

 

Sample Output

 

5

7

代码及注释如下:

/*我们知道k=i*x+r;其中x表示商即k/i,r表示余数即k%i;所以k=i*(k/i)+r;所以r=k-i*(k/i);所以就有sumr=nk-[1*(k/1)+2*(k/2)+....+n*(k/n)];而有一些连续区间的k/i一定相同,所以可以进行简化合并...并利用等差数列的公式进行求解令d=k/i; 则连续区间的最后一个数为j=k/d;所以可以结合等差数列求解....*/#include 
#include
#include
#include
using namespace std;typedef long long ll;ll n,k;int main(){ while (scanf("%lld%lld",&n,&k)!=EOF) { ll sum=n*k; if(n>k) n=k; for (int i=1;i<=n;) { ll d=k/i; ll j=k/d; if(j>n) j=n; sum=sum-d*((j-i+1)*(i+j)/2); i=j+1; } printf("%lld\n",sum); } return 0;}

 

转载地址:http://faaen.baihongyu.com/

你可能感兴趣的文章
Android x86模拟器Intel Atom x86 System Image配置与使用方法
查看>>
shell脚本兼容linux/unix与windows/cygwin的基础(注意处理好CR, LF, CR/LF 回车 换行的问题)
查看>>
【分享】手把手教你使用U盘安装Ubuntu系统
查看>>
Ubuntu下adb无法识别android设备的解决方法
查看>>
使用U盘安装Ubuntu系统的实践小结
查看>>
编译cscope-15.8a遇到的问题与解决方案
查看>>
ubuntu下海信Hisense E920 usb连接不上的处理与adb的连接
查看>>
findbugs的ant脚本实践
查看>>
Ubuntu 12.04 安装 Subversion 1.7
查看>>
scp port 22: Connection refused
查看>>
ubuntu12.04命令行下安装RabbitVCS
查看>>
自定义cscope-index
查看>>
(ubuntu)在andorid andk工程中使用ccache加速编译速度
查看>>
android graphics system学习资料汇总
查看>>
GDB
查看>>
Oracle RAC Failover 详解
查看>>
[转载]Oracle RAC客户端连接不稳定的解决方法
查看>>
ORA RAC ORA-12545:因目标主机或对象不存在,连接失败!
查看>>
证明两节点能正常failover的sql
查看>>
oracle10g rac 报ora-12545错误的解决方案 转载
查看>>