• CodeForces 483B Friends and Presents


     Friends and Presents
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.

    In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.

    Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.

    A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.

    Input

    The only line contains four positive integers cnt1cnt2xy (1 ≤ cnt1, cnt2 < 109cnt1 + cnt2 ≤ 1092 ≤ x < y ≤ 3·104) — the numbers that are described in the statement. It is guaranteed that numbers xy are prime.

    Output

    Print a single integer — the answer to the problem.

    Sample Input

    Input
    3 1 2 3
    Output
    5
    Input
    1 3 2 3
    Output
    4
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 typedef long long LL;
     9 LL cnt1, cnt2, x, y;
    10 
    11 bool check(LL v)
    12 {
    13     LL f1,f2,both,others,ff1,ff2,gf1,gf2;
    14      f1 = v / x;
    15      f2 = v / y;
    16      both = v / (x*y);
    17      others = v - f1 - f2 + both;
    18      ff1 = f1 - both;  
    19      ff2 = f2 - both;  
    20 
    21      gf1 = (cnt1 - ff2 >= 0 ? cnt1 - ff2 : 0);
    22      gf2 = (cnt2 - ff1 >= 0 ? cnt2 - ff1 : 0);
    23 
    24     return (gf1 + gf2 <= others);
    25 }
    26 
    27 int main()
    28 {
    29     while (scanf("%I64d%I64d%I64d%I64d", &cnt1, &cnt2, &x, &y) != EOF)
    30     {
    31         LL l=1, r=1e18;
    32         while (l<r)
    33         {
    34             LL m=(l+r)/2;
    35             if (check(m))
    36                 r=m;
    37             else
    38                 l=m+1;
    39         }
    40         printf("%I64d
    ",r);
    41     }
    42     return 0;
    43 }
    View Code
  • 相关阅读:
    Android ListView 的布局图标大小设置
    Android BaseAdapter 类 重写模版
    Fabric 介绍
    CentOS yum安装mysql
    JavaStringBuffer类常用方法简介
    Java流的简单使用:读取文件、写入文件(面试题:删除注释代码)
    Android数据库详解之二:数据库用法介绍
    JavaString类的方法及说明
    Android图像识别项目OpenCV(1):技术选型以及NDK搭建
    JDK(6u25)安装及相关知识
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771543.html
Copyright © 2020-2023  润新知