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
  • 相关阅读:
    每日一水 POJ8道水题
    编译和使用 MySQL C++ Connector
    j2ee model1模型完成分页逻辑的实现 详解!
    DB查询分析器访问EXCEL时,要在表名前后加上中括弧或双引号
    指向结构体变量的指针
    EOSS V3.0 企业运营支撑系统(基于RBAC原理的权限管理)
    MybatisGen1.0 Mybatis JavaBean Mapper生成工具
    The table name must be enclosed in double quotation marks or sqare bracket while accessing EXCEL by
    资源-Android:Android
    软件-开发软件:Android Studio
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771543.html
Copyright © 2011-2022 走看看