链接:https://vjudge.net/problem/UVA-1363

题意:给出n  k,当 i 属于 1~n 时 ,求解 n% i 的和

n 和 k 的范围都是 1 到 10^9;

商相同 的余数数列 是 公差为商 的 递减等差数列

应该让k / i相等的一连串k % i相加,举个例子:

100 / 34 = 2 ... 32

100 / 35 = 2 ... 30

100 / 36 = 2 ... 28

...

100 / 50 = 2 ... 0

递减等差数列通项公式:an=a1-(n-1)*d

前n项和公式:sum=n*a1-n*(n-1)*d/2;

#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll n,k,d,a,len,sum;
int main()
{
freopen("joseph.in","r",stdin);
freopen("joseph.out","w",stdout);
while(cin>>n>>k)
{
sum=;
for(ll i=;i<=n;i=i+len)
{
d=k/i;//公差
a=k%i;//递减等差数列的首项,最长递减到零结束
if(i>k)
{
sum=sum+k*(n-k);
break;
}
len=a/d+;//由递减等差数列的的通项公式an=a1+(n-1)*d解得数列递减到0的长度
len=min(len,n-i+);//最后一段等差数列可能没有递减到零,长度要另外判断
sum=sum+len*a-len*(len-)*d/;//等差数列前n项和公式
}
cout<<sum<<endl;
}
return ;
}

Problem J. Joseph’s Problem 约瑟夫问题--余数之和的更多相关文章

  1. UVa 1363 (数论 数列求和) Joseph's Problem

    题意: 给出n, k,求 分析: 假设,则k mod (i+1) = k - (i+1)*p = k - i*p - p = k mod i - p 则对于某个区间,i∈[l, r],k/i的整数部分 ...

  2. UVA 1363 Joseph's Problem 找规律+推导 给定n,k;求k%[1,n]的和。

    /** 题目:Joseph's Problem 链接:https://vjudge.net/problem/UVA-1363 题意:给定n,k;求k%[1,n]的和. 思路: 没想出来,看了lrj的想 ...

  3. 实验12:Problem J: 动物爱好者

    #define null ""是用来将字符串清空的 #define none -1是用来当不存在这种动物时,返回-1. 其实这种做法有点多余,不过好理解一些. Home Web B ...

  4. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  5. The Ninth Hunan Collegiate Programming Contest (2013) Problem J

    Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...

  6. Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量

    Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...

  7. Problem J: 求个最大值

    Problem J: 求个最大值 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 871  Solved: 663[Submit][Status][Web ...

  8. Problem J. Journey with Pigs

    Problem J. Journey with Pigshttp://codeforces.com/gym/241680/problem/J考察排序不等式算出来单位重量在每个村庄的收益,然后生序排列猪 ...

  9. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem J. Joke 水题

    Problem J. Joke 题目连接: http://codeforces.com/gym/100714 Description The problem is to cut the largest ...

随机推荐

  1. Python数据类型-3 布尔类型

    布尔类型 对于错.0和1.正与反,都是传统意义上的布尔类型. 但在Python语言中,布尔类型只有两个值,True与False.请注意,是英文单词的对与错,并且首字母要大写,不能其它花式变型. 布尔值 ...

  2. Windows驱动开发-IRP超时处理

    IRP被送到底层驱动程序以后,由于硬件设备的问题,IRP不能得到及时处理,甚至有可能永远不会被处理,这时候需要对IRP超时情况进行处理,一旦在规定时间内,IRP没有被处理,操作系统就会进入到IRP的处 ...

  3. tensorflow文本分类实战——卷积神经网络CNN

    首先说明使用的工具和环境:python3.6.8   tensorflow1.14.0   centos7.0(最好用Ubuntu) 关于环境的搭建只做简单说明,我这边是使用pip搭建了python的 ...

  4. python随机函数.2020.2.26

    随机生成函数: import random  //首先要引用random模板 print(random.randint(0,9))     //random的语法 random.randint(0,9 ...

  5. freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]

    FreeMarker template error:The following has evaluated to null or missing:==> product  [in templat ...

  6. Java日期时间API系列12-----Jdk8中java.time包中的新的日期时间API类,日期格式化,常用日期格式大全

    通过Java日期时间API系列10-----Jdk8中java.time包中的新的日期时间API类的DateTimeFormatter, 可以看出java8的DateTimeFormatter完美解决 ...

  7. 等级保护2.0-oracle

  8. [多校联考]SLON!!!

    题目描述 $SLON$是一个调皮的学生,为了让他静下心来,老师给他出了一道数学题:给定表达式$A$,$A$中含有变量$x$和$+,-,*,(,)$这些符号,括号成对出现,一个算术运算符均对应两个操作数 ...

  9. 十八 Spring的JDBC模板:引入外部属性文件

    配置外部属性文件 配置文件里引入属性文件,两种方式 第一种: 第二种: 引入属性文件的值: 测试: <?xml version="1.0" encoding="UT ...

  10. 【转载】C#常用控件属性及方法介绍

    C#常用控件属性及方法介绍                                               目录 1.窗体(Form) 2.Label (标签)控件 3.TextBox(文 ...