Codeforces Round #105 (Div. 2) / 148A Insomnia cure (枚举 || 数论)
来源:互联网 发布:js 等比例缩放图片 编辑:程序博客网 时间:2024/06/01 10:02
«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.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every 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.
How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of d dragons?
Input data contains integer numbers k, l, m, n and d, each number in a separate line (1 ≤ k, l, m, n ≤ 10, 1 ≤ d ≤ 105).
Output the number of damaged dragons.
123412
12
234524
17
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];elseret -= n / div[j];}printf("%d",ret);}
- Codeforces Round #105 (Div. 2) / 148A Insomnia cure (枚举 || 数论)
- [Codeforces] 148A - Insomnia cure
- CodeForces-148A-Insomnia cure
- CodeForces 148A Insomnia cure
- codeforces-148A-Insomnia cure
- codeforces 148A Insomnia cure
- Problem--148A--Codeforces--A. Insomnia cure
- codeforces 148A(Insomnia cure) Java
- 148A - Insomnia cure
- 148A - Insomnia cure
- codeforce 148->A. Insomnia cure
- Insomnia cure CodeForces
- A. Insomnia cure
- CF148 A Insomnia cure
- Codeforces Round #368 (Div. 2) A(水题) B(枚举 思维) C(数论 勾股数)
- Codeforces刷题之路——148A Insomnia cure
- CodeForce 148A Insomnia Cure 公倍数计算问题
- Codeforces Round #198 (Div. 2) / 340A The Wall (数论)
- Flex 滚动条外观
- BigDecimal类型(+ - * /)所用的属性
- C++11 理解 (十七) 之 变长参数模板
- dhcpd交叉编译
- 正则表达式
- Codeforces Round #105 (Div. 2) / 148A Insomnia cure (枚举 || 数论)
- 安装Hbase Thrift C++ Client
- 自己写的一个增强版本的 RRDtool fetch
- JAVA整合Flex导出数据库中的数据 (续集2)
- 学习matlab的资源网站
- 在C#中,远程连接Oracle数据库(不安装客户端,无需多余配置)
- zend framework多模块多Layout配置
- Ural 1019. Line Painting
- Record mode Concept in SAP BI