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



  • 相关阅读:
    Socket异步通信
    以读取博客园随笔备份为例 将xml 序列化成json,再序列化成对象
    NhibernateProfiler写个自动破解工具
    关于下载GAE High Replication Datastore数据
    .text 0.958 数据添加
    C#实现RTP数据包传输参照RFC3550
    在线商城表结构
    相似字符串
    .net 4.0 的Socket写的支持跨平台双工的轻量级通讯组件
    写一个迷你版Smarty模板引擎,对认识模板引擎原理非常好(附代码)
  • 原文地址:https://www.cnblogs.com/z-712/p/12082543.html
Copyright © 2020-2023  润新知