light oj 1236 【大数分解】
来源:互联网 发布:php在线讲解 编辑:程序博客网 时间:2024/04/30 16:17
给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,……em,
则结果为((1+2*e1)*(1+2*e2)……(1+2*em)+1)/2.
//light oj 1236 大数分解素因子#include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <math.h> #include <ctype.h> #include <time.h> #include <queue> #include <iterator> const int MAXN = 10000200;bool com[MAXN];int primes;long long prime[MAXN/10];long long ans, t, n;void init(int n){primes = 0;memset(com, false, sizeof(com));com[0] = com[1] = true;for (int i = 2; i <= n; ++i){if (!com[i]){prime[++primes] = i;}for (int j = 1; j <= primes && i*prime[j] <= n; ++j){com[i*prime[j]] = true;if (!(i % prime[j]))break;}}}long long solve(long long n)//大数分解{ans = 1;for (int i = 1; i<=primes && prime[i] * prime[i] <= n; i++){if (n % prime[i] == 0){t = 1;n /= prime[i];while (n%prime[i] == 0){t++;n /= prime[i];}ans *= (1 + 2 * t);}}if (n > 1)ans *= 3;return (1+ans) / 2;}int main(){ init(10000000);int tt, cases = 1;scanf("%d",&tt);while (tt--){scanf("%lld",&n);long long res = solve(n);printf("Case %d: %lld\n",cases++,res);}return 0;}
0 0
- light oj 1236 【大数分解】
- Light Oj 1214 大数整除
- Light oj--1214(大数整除)
- light oj 1236 Pairs Forming LCM(整数分解)
- 【light-oj】-大数整除(字符串)
- Light Oj 1236
- [整数分解+dfs] light oj 1220 Mysterious Bacteria
- Light OJ 1014 Ifter Party [因子分解]【数论】
- Light OJ 1138 (二分查找+分解阶乘)
- light oj
- light oj
- Light OJ
- Light OJ
- Light OJ 1236 Race 第二类斯特林数
- Light OJ 1236 Pairs Forming LCM
- Light OJ 1318 Strange Game 组合数+快速幂+分解因子
- Light OJ 1341 Aladdin and the Flying Carpet Pollard_rho整数分解+DFS
- Light OJ 1341 Aladdin and the Flying Carpet(唯一分解定理)
- 欢迎使用CSDN-markdown编辑器
- PYTHON 一些基础面试题目总结
- Java学习3
- linux中likely与unlikely
- MFC中隐藏、显示菜单栏
- light oj 1236 【大数分解】
- 18大经典数据挖掘算法小结
- Ubuntu server 14.04 配置Memcache,以及Memcache的简单使用
- 快速排幂-----Digit Rightmost
- struct和typedef struct区别详解
- csdn 黑白球
- The C10K problem翻译
- 等高布局
- python面试题大全