• 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 }



  • 相关阅读:
    jQuery横向手风琴
    jQuery宽屏游戏焦点图
    手风琴式相册图片展开效果
    鼠标悬停图片分享按钮动画
    jQuery水平滑动菜单
    jQuery图片水平滑动延迟加载动画
    jQuery悬浮焦点图宽屏
    jQuery自定义美化下拉框
    纯CSS3垂直动画菜单
    面向服务与微服务架构
  • 原文地址:https://www.cnblogs.com/z-712/p/12082543.html
Copyright © 2020-2023  润新知