zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 13 C. Joty and Chocolate 水题

    C. Joty and Chocolate

    题目连接:

    http://www.codeforces.com/contest/678/problem/C

    Description

    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 n, a, b, p 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.

    Sample Input

    5 2 3 12 15

    Sample Output

    39

    Hint

    题意

    有1到n n个数,如果k%a0,那么给p元,如果k%b0,那么给q元

    如果k%a0||k%b0,那么给p元或者q元

    问你最多给多少

    题解:

    k%a0||k%b0 > k%lcm(a,b)0 给max(p,q)元

    然后搞一波就好了……

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    long long gcd(long long a,long long b)
    {
        if(b==0)return a;
        return gcd(b,a%b);
    }
    long long lcm(long long a,long long b)
    {
        return a*b/gcd(a,b);
    }
    long long n,a,b,p,q;
    int main()
    {
        cin>>n>>a>>b>>p>>q;
        long long ans1 = n/a;
        long long ans2 = n/b;
        long long ans3 = n/lcm(a,b);
        ans1-=ans3,ans2-=ans3;
        cout<<ans1*p+ans2*q+(ans3)*max(p,q)<<endl;
    }
  • 相关阅读:
    C++:delete和delete[]释放内存的区别
    C++:四种必须使用初始化列表情况
    C++:获取数组长度
    C++:构造函数默认的参数声明
    java 的开源wiki维基系统
    openfire 最大连接数调优
    即时通讯服务器的对比
    分分钟带你玩转 Web Services
    让git忽略ignore所有文件,只对某些文件进行版本控制
    miracast 协议wifi display
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5582694.html
Copyright © 2011-2022 走看看