Codeforces Round #105 (Div. 2) / 148A Insomnia cure (枚举 || 数论)_枚举输入

  • 阿里云国际版折扣https://www.yundadi.com

  • 阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6


    A. Insomnia cure

    http://codeforces.com/problemset/problem/148/A

    time limit per test

    memory limit per test

    input

    output

    «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.

    k-th dragon got punched in the face with a frying pan. Every l-th dragon got his tail shut into the balcony door. Every m-th dragon got his paws trampled with sharp heels. Finally, she threatened every n-th dragon to call her mom, and he withdrew in panic.

    d

    Input

    k, l, m, n and d, each number in a separate line (1 ≤ k, l, m, n ≤ 10, 1 ≤ d ≤ 105).

    Output

    Output the number of damaged dragons.

    Sample test(s)

    input

    1 2 3 4 12

    output

    12

    input

    2 3 4 5 24

    output

    17

    Note

    In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.

    In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.


    暴力代码:

    /*30ms,0KB*/
    
    #include <cstdio>
    
    int main(void)
    {
    	int k, l, m, n, d, s = 0;
    	scanf("%d%d%d%d%d", &k, &l, &m, &n, &d);
    	for (int i = 1; i <= d; ++i)
    		if (!(i % k && i % m && i % n && i % l))
    			s++;
    	printf("%d\n", s);
    	return 0;
    }


    神牛写的数论代码:(没看懂)

    /*30ms,0KB*/
    
    #include <cstdio>
    #include <vector>
    using namespace std;
    
    int v[4], n;
    bool bio[4][4];
    
    inline int gcd(int a, int b)
    {
    	int ret = 1;
    	for (int i = 2; i <= a; ++i)
    		if (a % i == 0 && b % i == 0)
    			ret = i;
    	return ret;
    }
    
    inline int lcm(int a, int b)
    {
    	return a / gcd(a, b) * b;///为防止可能的数据超范围,先除再乘要更好。
    }
    
    vector<int> rek(int i, int k, vector<int> w)
    {
    	if (k == 0)
    	{
    		int ret = w[0];
    		for (int j = 1; j < (int) w.size(); ++j)
    			ret = lcm(ret, w[j]);
    		return vector<int> (1, ret);
    	}
    	if (i == 4)
            return vector<int>();
    	vector<int> ret;
    	vector <int> ret2 = rek(i + 1, k, w);
    	for (int j = 0; j < (int)ret2.size(); ++j)
    		ret.push_back(ret2[j]);
    	w.push_back(v[i]);
    	vector<int> ret1 = rek(i + 1, k - 1, w);
    	for (int j = 0; j < (int)ret1.size(); ++j)
    		ret.push_back(ret1[j]);
    	return ret;
    }
    
    int main(void)
    {
    	int ret = 0;
    	scanf("%d%d%d%d%d", &v[0], &v[1], &v[2], &v[3], &n);
    	for (int i = 1; i <= 4; ++i)
    	{
    		vector<int> div = rek(0, i, vector<int>());
    		for (int j = 0; j < (int)div.size(); ++j)
    			if (i % 2)
    				ret += n / div[j];
    			else
    				ret -= n / div[j];
    	}
    	printf("%d",ret);
    }



  • 阿里云国际版折扣https://www.yundadi.com

  • 阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

    “Codeforces Round #105 (Div. 2) / 148A Insomnia cure (枚举 || 数论)_枚举输入” 的相关文章

    ThinkPHP怎么获取发布者地址标注 - 编程语言

    本文小编为大家详细介绍“ThinkPHP怎么获取发布者地址标注”,内容详细,步骤清晰,细节处理妥当,希望这篇“ThinkPHP怎么获取发布者地址标注”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。 一、使用 IP...

    Java中的枚举怎么使用 - 开发技术

    本篇内容主要讲解“Java中的枚举怎么使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Java中的枚举怎么使用”吧!枚举(enum)枚举是一个被命名的整型常数的集合,用于声明一组带标识符的常数。枚举在曰常生活中很常见,例...

    回 调

    话不多说,上代码 #include<iostream> using namespace std; typedef int(*ABCD)(char* p);//这里的ABCD可以用任意字符串替换,不过一般用类似CallBack的字符串 int...

    怎么搭建php网站并实现局域网访问 - 编程语言

    本篇内容主要讲解“怎么搭建php网站并实现局域网访问”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么搭建php网站并实现局域网访问”吧! 一、搭建PHP环境首先,搭建PHP网站需要环境支持,即...

    python免杀技术shellcode的加载与执行方法是什么 - 开发技术

    本篇内容主要讲解“python免杀技术shellcode的加载与执行方法是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“python免杀技术shellcode的加载与执行方法是什么”吧!0x01 生成shellcode...

    ThingsBoard——Rest API获取token和刷新token

    ThingsBoard的REST API文档使用的是Swagger大多数的接口都可以通过这个地址来查看和测试后面带锁图标的接口表示需要鉴权 http://{{YOUR_HOST}}:{{PORT}}/swagger-ui.html 一、登录获取token 登录接口在login-endpoin...