LightOJ 1035 Intelligent Factorial Factorization
来源:互联网 发布:知足知不足的阅读答案 编辑:程序博客网 时间:2024/05/22 03:13
题目:
Description
Given an integer N, you have to prime factorize N! (factorial N).
Input
Input starts with an integer T (≤ 125), denoting the number of test cases.
Each case contains an integer N (2 ≤ N ≤ 100).
Output
For each case, print the case number and the factorization of the factorial in the following format as given in samples.
Case x: N = p1 (power of p1) * p2 (power of p2) * ...
Here x is the case number, p1, p2 ... are primes in ascending order.
Sample Input
3
2
3
6
Sample Output
Case 1: 2 = 2 (1)
Case 2: 3 = 2 (1) * 3 (1)
Case 3: 6 = 2 (4) * 3 (2) * 5 (1)
结论是很简单的,不超过n的素数都会输出,超过n的都不会输出。
而且,2一定在里面,也就是说,2一定是第一个,这样就很方便了。
代码:
#include<iostream>#include<stdio.h>using namespace std;int degree_in_fact(int m, int p){if (m)return degree_in_fact(m / p, p) + m / p;return 0;}bool isprime(int n){for (int i = 3; i*i <= n; i += 2)if (n%i == 0)return false;return true;}int main(){int t, n;cin >> t;for (int cas = 1; cas <= t; cas++){cin >> n;cout << "Case " << cas << ": " << n << " = 2 (" << degree_in_fact(n, 2) << ")";for (int i = 3; i <= n; i += 2)if (isprime(i))
cout << " * " << i << " (" << degree_in_fact(n, i) << ")";cout << endl;}return 0;}
不知道degree_in_fact这个函数的,请点击打开我的博客
2 0
- LightOJ 1035 Intelligent Factorial Factorization
- LightOJ 1035 Intelligent Factorial Factorization
- LightOJ 1035 Intelligent Factorial Factorization
- Intelligent Factorial Factorization LightOJ
- lightoj 1035 Intelligent Factorial Factorization 因式分解
- LightOJ 1035 Intelligent Factorial Factorization 全排列
- LightOJ 1035 - Intelligent Factorial Factorization (求因子)
- LightOJ 1035 Intelligent Factorial Factorization 因子分解水题
- LightOJ 1035 Intelligent Factorial Factorization [预处理+一半的 质因子分解]【数论】
- Light OJ 1035 - Intelligent Factorial Factorization
- Light OJ 1035 Intelligent Factorial Factorization
- LightOJ1035 Intelligent Factorial Factorization(算数基本定理)
- LightOJ 1045 Digits of Factorial
- LightOJ 1045 Digits of Factorial
- LightOJ 1045 Digits of Factorial
- LightOJ - 1045 Digits of Factorial
- lightoj 1045 - Digits of Factorial
- 【LightOJ 1045 Digits of Factorial】
- [李景山php]每天laravel-20161017|ResponseTrait.php
- Android蓝牙源码分析——关于GKI
- NAT详解:基本原理、穿越技术(P2P打洞)、端口老化等
- 图结构练习——BFSDFS——判断可达性
- angularjs定时任务的设置与清除
- LightOJ 1035 Intelligent Factorial Factorization
- mysql注册以及安装之后无法连接解决方法
- 强制断开SqlServer连接
- 手机照片误删怎么找回
- eclipse起动无响应,停留在Loadingworkbench状态
- [李景山php]每天laravel-20161017|UploadedFile.php
- FZU 最大黑区域
- 解决:System.Data.SqlClient.SqlException: 超出了存储过程、函数、触发器或视图的最大嵌套层数(最大层数为 32).
- 戏说设计模式-工厂模式