zoukankan      html  css  js  c++  java
  • codeforces 678C C. Joty and Chocolate(水题)

    题目链接:

    C. Joty and Chocolate

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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

    题意:

    a的倍数给p个巧克力,b的倍数q个巧克力,即是a又是b的倍数都可以,那么[1,n]一共可以得到多少巧克力;

    思路:

    跟容斥定理差不多,求一个最小公倍数,就好了;

    AC代码

    //#include <bits/stdc++.h>
    
    #include <iostream>
    #include <queue>
    #include <cmath>
    #include <map>
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    using namespace std;
    #define Riep(n) for(int i=1;i<=n;i++)
    #define Riop(n) for(int i=0;i<n;i++)
    #define Rjep(n) for(int j=1;j<=n;j++)
    #define Rjop(n) for(int j=0;j<n;j++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    typedef unsigned long long uLL;
    typedef long long LL;
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=0x3f3f3f3f;
    const int N=1e6+8;
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
    
    LL n,a,b,p,q;
    
    LL gcd(LL x,LL y)
    {
        if(y==0)return x;
        return gcd(y,x%y);
    }
    LL lcm(LL x,LL y)
    {
        LL temp=gcd(x,y);
        return x/temp*y;
    }
    int main()
    {
        read(n);
        read(a);
        read(b);
        read(p);read(q);
        LL ans=n/a*p+n/b*q-n/lcm(a,b)*min(p,q);
        cout<<ans<<"
    ";
    
        return 0;
    }



  • 相关阅读:
    用java代码调用shell脚本执行sqoop将hive表中数据导出到mysql
    用sqoop将mysql的数据导入到hive表中
    windows下启动mysql服务的命令行启动和手动启动方法
    使sqoop能够启用压缩的一些配置
    简易安装sqoop
    sqoop一些语法的使用
    mysql 视图
    MySQL 函数大全及用法示例
    MySQL 触发器 -1
    MySQL 函数
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5585851.html
Copyright © 2011-2022 走看看