UVa Problem Solution: 10139 - Factovisors
来源:互联网 发布:学校排课软件 编辑:程序博客网 时间:2024/05/21 09:32
We check each of the prime factors of m to see if n! has enough prime factors of the same value. If so, m can divide n!, otherwise m can not divide n!.
Code:
- /***************************************************************************
- * Copyright (C) 2008 by Liu Kaipeng *
- * LiuKaipeng at gmail dot com *
- ***************************************************************************/
- /* @JUDGE_ID 00000 10139 C++ "Factovisors" */
- #include <algorithm>
- #include <cmath>
- #include <cstdio>
- #include <cstring>
- #include <deque>
- #include <fstream>
- #include <iostream>
- #include <list>
- #include <map>
- #include <queue>
- #include <set>
- #include <stack>
- #include <string>
- #include <vector>
- using namespace std;
- bool is_factorial_divide(int n, int m)
- {
- if (m == 0) return false;
- if (n == 0 && m == 1) return true;
- for (int f = 2, mf = sqrt(m) + 1; m > n && f < mf; ++f) {
- int c = 0;
- for (; m % f == 0; m /= f, ++c) {}
- for (int nf = f; c > 0 && nf <= n; c -= n / nf, nf *= f) { }
- if (c > 0) return false;
- }
- return m <= n;
- }
- int main(int argc, char *argv[])
- {
- #ifndef ONLINE_JUDGE
- freopen((string(argv[0]) + ".in").c_str(), "r", stdin);
- freopen((string(argv[0]) + ".out").c_str(), "w", stdout);
- #endif
- char const *msg[] = {
- " does not divide ",
- " divides ",
- };
- for (int n, m; cin >> n >> m; )
- cout << m << msg[is_factorial_divide(n, m)] << n << "!/n";
- return 0;
- }
- UVa Problem Solution: 10139 - Factovisors
- UVa Problem 10139 Factovisors (阶乘与整除)
- UVa 10139 Factovisors
- uva 10139 factovisors
- Uva 10139 Factovisors
- UVa 10139 Factovisors
- UVa 10139 - Factovisors
- UVa 10139 - Factovisors
- UVA 10139 Factovisors
- UVA 10139 Factovisors(数论)
- 【 UVa 10139】 Factovisors 【 m | n!? 】
- PC/UVa 题号: 110704/10139 Factovisors
- UVa 10139 Factovisors (阶乘能否整除?)
- UVa-10139 Factovisors -(阶乘的整除)
- UVa Problem Solution: 10189 - Minesweeper
- UVa Problem Solution: 10033 - Interpreter
- UVa Problem Solution: 10050 - Hartals
- UVa Problem Solution: 10149 - Yahtzee
- flash与javacript通信(1)
- 定时自动重启IIS和定时重启服务器
- urlEncode (vc++)
- 好名字全集
- 无Dll插入进程、下载者VC源代码
- UVa Problem Solution: 10139 - Factovisors
- utf8, unicode, gb2312 编码转换vc++
- java反射技术
- 最通用的Ajax中文乱码解决方案。
- DBA的职责和任务(转自oracle中文技术论坛)
- 愛我嗎?
- WinCE 流驱动一步一步来(转载)
- Axure RP Pro - 相关问题 - 线框中的字号与原型中的字号的关系
- 与游戏结合的建材网店