#include <iostream>
typedef long long ll;
using namespace std;
bool ll_is_valid(ll t, ll N, ll x, ll y)
{
return t / x + (t - x) / y >= N;
}
ll f(ll N, ll x, ll y)
{
ll R = 1;
while (!ll_is_valid(R,N,x,y)) R *= 2;
ll L = R / 2;
while(R - L > 1)
{
ll M = (L + R) / 2;
if (!ll_is_valid(M,N,x,y)) {L = M;}
else {R = M;}
}
return R;
}
int main()
{
ll N,x,y;
cin >> N >> x >> y;
if(x > y) swap( x, y );
cout << f(N, x, y) << std::endl;
}
begin
var (cost, t, k) : = (arr(15, 70, 125, 230, 440), arr(1, 5, 10, 20, 60), new integer[5]);
var n : = readinteger('n-> ');
for var i : = 4 downto 0 do
begin
k[i] : = n div t[i]; n : = n mod t[i];
end;
if k[0] * cost[0] > = cost[1] then begin k[0] : = 0; inc(k[1]); end;
if k[0] * cost[0] + k[1] * cost[1] > = cost[2] then
begin
k[0] : = 0; k[1] : = 0; inc(k[2]);
end;
if k[0] * cost[0] + k[1] * cost[1] + k[2] * cost[2] > = cost[3] then
begin
k[0] : = 0; k[1] : = 0; k[2] : = 0; inc(k[3]);
end;
if k[0] * cost[0] + k[1] * cost[1] + k[2] * cost[2] + k[3] * cost[3] > = cost[4] then
begin
k[0] : = 0; k[1] : = 0; k[2] : = 0; k[3] : = 0; inc(k[4]);
end;
for var i : = 0 to 4 do writelnformat('{0} билет(ов)- {1} штук(а)', t[i], k[i]);
end.
пример(1):
n-> 37
1 билет(ов)- 0 штук(а)
5 билет(ов)- 0 штук(а)
10 билет(ов)- 0 штук(а)
20 билет(ов)- 0 штук(а)
60 билет(ов)- 1 штук(а)
пример(2):
n-> 35
1 билет(ов)- 0 штук(а)
5 билет(ов)- 1 штук(а)
10 билет(ов)- 1 штук(а)
20 билет(ов)- 1 штук(а)
60 билет(ов)- 0 штук(а)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List res = new List();
for(int i=1000;i<10000; i++)
{
int[] sb=new int[4];
sb[0] = i / 1000;
sb[1] = (i / 100) % 10;
sb[2] = (i % 100)/10;
sb[3] = i % 10;
if (sb.Sum() == 15)
res.Add(i);
}
Console.WriteLine("Искомые числа:");
for (int i = 0; i < res.Count; i++)
Console.Write("{0} ", res[i]);
Console.ReadKey();
}
}
}
Объяснение: