zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    IntelliJ IDEA 2017 反向代理工具新方法激活
    如何去掉idea里mybatis的.xml文件 sql 语句背景色
    eclipse、idea切换大小写的快捷键
    pageHelper没有分页效果的问题
    springboot使用thymeleaf 解析异常
    SpringBoot发送简单文本邮件
    IDEA中使用git详细步骤
    解决 git branch -a 无法全部显示远程的分支,只显示master分支
    git常用命令
    异常处理
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771543.html
Copyright © 2011-2022 走看看