zoukankan      html  css  js  c++  java
  • Educational codeforces Round11 C

    C. Joty and Chocolate

     

    Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.

    An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a and b can be either painted Red or Blue.

    After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.

    Note that she can paint tiles in any order she wants.

    Given the required information, find the maximum number of chocolates Joty can get.

    Input

    The only line contains five integers nabp and q (1 ≤ n, a, b, p, q ≤ 109).

    Output

    Print the only integer s — the maximum number of chocolates Joty can get.

    Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

    Examples
    input
    5 2 3 12 15
    output
    39

    input
    20 2 3 3 5
    output
    51

    小析:有(1~n)块瓷砖,下标可以被a或b整除可以被涂上对应颜色,每种颜色获得的巧克力数不同,若可被a and b 整除,可以选择一种颜色涂抹。要求获得最多的巧克力数
    这道题有点类似容斥定理吧
     1 #include <bits/stdc++.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 #include <stdio.h>
     5 #include <cstdlib>
     6 
     7 
     8 using namespace std;
     9 typedef long long LL;
    10 LL gcd(LL a,LL b){
    11     return a%b==0?b:gcd(b,a%b);
    12 }
    13 
    14 int main(){
    15     LL n,a,b,p,q;
    16     cin>>n>>a>>b>>p>>q;
    17     LL lcm=a/gcd(a,b)*b;
    18     LL x=n/a,y=n/b,z=n/lcm;
    19     LL sum=x*p+y*q;
    20     if(z)
    21         sum=(p>q)?sum-z*q:sum-z*p;
    22     cout<<sum<<endl;
    23 }



  • 相关阅读:
    LINUX查看进程开始时间、结束时间、运行时间
    excel字符处理函数
    oracle RMAN参数配置详解
    Linux添加双IP
    免费软电话 — XLite 的安装及配置向导
    Asterisk实现寻呼对讲广播的Page()命令详解
    自动化工具的重要性
    负载均衡之应用请求路由模块的使用(ARR)(七)[使用ARR来实现主机名共享]
    负载均衡之应用请求路由模块的使用(ARR)(二)[安装]
    需求管理随笔
  • 原文地址:https://www.cnblogs.com/z-712/p/12082543.html
Copyright © 2011-2022 走看看