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 }



  • 相关阅读:
    有return的情况下try catch finally的执行顺序
    for循环和foreach循环效率对比
    SpringBoot_数据访问-整合MyBatis-配置版MyBatis
    作品
    HTML——招生信息网(bootstrap、WOW动画、blueimp-gallery图片展示插件)
    HTML——信息技术基础精品课程
    HTML——校友会(bootstrap)
    毕设——社区志愿者信息管理系统
    HTML笔记——JS下载.json文件
    HTML笔记——bootstrap-select、table、tableExport、layer
  • 原文地址:https://www.cnblogs.com/z-712/p/12082543.html
Copyright © 2011-2022 走看看