UVa 160 Factors and Factorials (数论)
来源:互联网 发布:广东省大数据产业园 编辑:程序博客网 时间:2024/05/18 04:29
160 - Factors and Factorials
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=96
题目点这:http://uva.onlinejudge.org/external/1/160.pdf
思路:遍历1~n计算质因子个数即可。
你若还想再快点的话,就用[n/p]+[n/p^2]+[n/p^3]+...+1在O(log n/log p)的时间内统计出n!的质因子p的个数。(不过此题n太小,两种方法在时间上相差不大)
完整代码:
/*0.016s*/#include<cstdio>#include<cmath>#include<cstring>int prime[100], c, ans[100];bool vis[110];inline void create_prime(){int i, j;for (i = 2; i <= 11; ++i)if (!vis[i]){prime[c++] = i;for (j = i * i; j < 110; j += i)vis[j] = true;}for (; i < 110; ++i)if (!vis[i])prime[c++] = i;}int main(void){create_prime();int n, temp;while (scanf("%d", &n), n){memset(ans, 0, sizeof(ans));printf("%3d! =", n);for (int i = 2; i <= n; i++){temp = i;for (int j = 0; j < c && prime[j] <= i; j++){while (temp % prime[j] == 0){++ans[prime[j]];temp /= prime[j];}}}for (int i = 0, j = 0; prime[i] <= n; i++, j++){if (j % 15 == 0 && j) printf("\n ");printf("%3d", ans[prime[i]]);}putchar('\n');}return 0;}
- UVa 160 Factors and Factorials (数论)
- UVa 160 - Factors and Factorials
- UVa 160-Factors and Factorials
- UVa 160 Factors and Factorials
- UVa 160 Factors ans Factorials(数论)
- UVa OJ 160 Factors and Factorials
- JOJ1775:Factors and Factorials
- Factors and Factorials
- uva160 Factors and Factorials
- Uva160——Factors and Factorials
- uva 11159 Factors and Multiples
- uva 11159 Factors and Multiples
- UVA 11159Factors and Multiples (最大独立集)
- Factorials and Trailing Zeroes
- UVa10484 - Divisibility of Factors(数论)
- UVA 10375 Choose and divide(数论)
- UVA - 10375Choose and divide(数论)
- UVa 583-Prime Factors
- SEO-页面各个元素的权重比例
- 【书籍推荐】GUI应用程序移植
- MySQL负载均衡-2:nginx 实现mysql的负载均衡
- IOS学习笔记(一)之安装开发环境与工具与第一个IOS应用程序
- uva 10110 Light, more light
- UVa 160 Factors and Factorials (数论)
- 父窗口调用子窗口的按钮
- 初学者学Java(十二)
- Linux的几个基本的系统操作命令
- ora-00600 [4000]实战恢复
- poj1062dijkstra
- 【书籍推荐】深入解析Windows操作系统(第4版)
- 父窗口调用子窗口的按钮
- 窗口站与桌面