zoukankan      html  css  js  c++  java
  • Codeforces483B——二分——Friends and Presents

    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
    /*
    题目要求最大值的最小 再看看数据1e9肯定二分
    推荐博文——http://www.cnblogs.com/windysai/p/4058235.html,写的很详细了,尤其那个图,没必要再阐述一遍
    
    */
    #include <bits/stdc++.h>
    using namespace std;
    
    const long long  inf = 1e16+100;
    long long  cnt1, cnt2, x, y;
    bool check(long long  xx)
    {
        long long  temp1 = xx/x;
        long long  temp2 = xx/y;
        long long  temp12 = xx/(x*y);
        long long  other = xx - temp1 - temp2 + temp12;
        long long  temp11 = temp1 - temp12;
        long long  temp22 = temp2 - temp12;
        long long  ans1 = cnt1 - temp22;
        long long  ans2 = cnt2 - temp11;
        if(ans1 < 0) ans1 = 0;
        if(ans2 < 0) ans2 = 0;
        return ans1 + ans2 <= other;
    }
    
    int main()
    {
       while(~scanf("%lld%lld%lld%lld", &cnt1, &cnt2, &x, &y)){
    
           long long  l = 1, r = inf;
           while(l <= r){
              // printf("%lld %lld
    ", l, r);
               long long  mid = l + r >> 1;
               if(!check(mid)){
                   l = mid + 1  ;
               }
               else r = mid - 1;
           }
           printf("%lld
    ", l);
       }
       return 0;
    }
    

      

  • 相关阅读:
    MySQL -- select count(1) 计算一共有多百少符合条件的行
    Python3 -- 文件I/O总结(with、read、write、txt、CSV等)
    Linux -- wget 之 FTP篇
    Linux -- head/tail 查看文件的指定行数
    linux -- 查看linux磁盘容量和文件夹所占磁盘容量
    Linux -- 查询某个文件夹下的文件数量
    Python3 -- 查看python安装路径以及pip安装的包列表及路径
    Python3 --Linux 编码注释# -*- coding:utf-8 -*-
    VisualStudio2013 如何打开之前版本开发的(.vdproj )安装项目
    const int *p与int *const p的区别(转:csdn,suer0101)
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4695785.html
Copyright © 2011-2022 走看看