kk people want to split nn candies between them. Each candy should be given to exactly one of them or be thrown away.

The people are numbered from 11 to kk, and Arkady is the first of them. To split the candies, Arkady will choose an integer xx and then give the first xx candies to himself, the next xx candies to the second person, the next xx candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by xx) will be thrown away.

Arkady can't choose xx greater than MM as it is considered greedy. Also, he can't choose such a small xxthat some person will receive candies more than DD times, as it is considered a slow splitting.

Please find what is the maximum number of candies Arkady can receive by choosing some valid xx.

Input

The only line contains four integers nn, kk, MM and DD (2≤n≤10182≤n≤1018, 2≤k≤n2≤k≤n, 1≤M≤n1≤M≤n, 1≤D≤min(n,1000)1≤D≤min(n,1000), M⋅D⋅k≥nM⋅D⋅k≥n) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.

Output

Print a single integer — the maximum possible number of candies Arkady can give to himself.

Note that it is always possible to choose some valid xx.

Examples
input

Copy
20 4 5 2
output

Copy
8
input

Copy
30 9 4 1
output

Copy
4
Note

In the first example Arkady should choose x=4x=4. He will give 44 candies to himself, 44 candies to the second person, 44 candies to the third person, then 44 candies to the fourth person and then again 44candies to himself. No person is given candies more than 22 times, and Arkady receives 88 candies in total.

Note that if Arkady chooses x=5x=5, he will receive only 55 candies, and if he chooses x=3x=3, he will receive only 3+3=63+3=6 candies as well as the second person, the third and the fourth persons will receive 33candies, and 22 candies will be thrown away. He can't choose x=1x=1 nor x=2x=2 because in these cases he will receive candies more than 22 times.

In the second example Arkady has to choose x=4x=4, because any smaller value leads to him receiving candies more than 11 time.

数学题,d比较小,枚举d

贪心思考,最好应该是第一个人取i次,其他人取i-1次

x*i+x*(i-1)*(k-1)<=n

若x>m 取x=m 然后重新判断是否可以到 i 组

//#include <bits/stdc++.h>
#include<iostream>
#include<stack>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (ll i = (a); i <= (b); i++)
#define FFor(i, a, b) for (int i = a; i >= (b); i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int N = ;
const int M=;
// name*******************************
ll n,k,m,d;
ll t;
ll ans=;
// function****************************** //***************************************
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
cin>>n>>k>>m>>d;
For(i,,d)
{
ll x=n/((i-)*k+);
if(!x)break;
if(x>m)x=m;
if(n/(k*x)+((n%(k*x)>=x)?:)!=i)continue;
ans=max(ans,x*i);
}
cout<<ans;
return ;
}

最新文章

  1. Linux下快速迁移海量文件的操作记录
  2. PHP的字符串函数
  3. php代码优化系列 -- array_walk 和 foreach, for 的效率的比较
  4. iOS开发MAC下配置Svn和Git
  5. jsp\struts1.2\struts2 中文件上传(转)
  6. Java后台传前台json数组
  7. Problem A 栈
  8. 用widthStep的方法来增加某范围的像素----与imageROI对比
  9. Microsoft Visual Studio Web 创作组件安装失败的解决方法
  10. 使用ThinkPHP开发中MySQL性能优化的最佳21条经验
  11. 关于三星手机照相机调用适配问题Android
  12. BadUSB的防范研究
  13. 初试PL/SQL并行编程
  14. WCF技术剖析之二十四: ServiceDebugBehavior服务行为是如何实现异常的传播的?
  15. json-lib之复杂数据类型的转换
  16. about-php
  17. 史上最污技术解读,让你秒懂IT术语(转载)
  18. php文件与HTML页面的数据交互
  19. 在VSCode中成功安装Go相关插件问题:tools failed to install.
  20. Java并发编程:线程池的使用(转载)

热门文章

  1. POJ1149(最大流)
  2. cf711D. Directed Roads(环)
  3. postman获取全局
  4. 活字格Web应用平台学习笔记2-基础教程-开始
  5. MySql&#160;利用crontab实现MySql定时任务
  6. TagCloudView云标签的灵活运用
  7. mongodb的搭建
  8. MariaDB实现主从配置及读写分离(一)
  9. mysqldump: Error 2013
  10. centos 安装elk监控