质因数分解codevs3164

来源:互联网 发布:如何设计装修淘宝店铺 编辑:程序博客网 时间:2024/06/16 11:32
题目描述 Description

(多数据)给出t个数,求出它的质因子个数。

数据没坑,难度降低。

输入描述 Input Description

第一行 t

之后t行 数据

输出描述 Output Description

t行 分解后结果(质因子个数)

样例输入 Sample Input

2

11

6

样例输出 Sample Output

1

2

数据范围及提示 Data Size & Hint

(样例解释)11自己本身是一个质数,所以计入其中。

顺便提示:t<=100000。每个数小于long long unsigned 呵呵


这道题就是把一个数一步步的分解成质数,问最多能分解成多少个质数

像27最多可以分解为3个质数:3 3 3

so,枚举。

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int t,tot;
long long n;
scanf("%d",&t);
while(t--)
{
tot = 0;
scanf("%lld",&n);
for(int j = 2; j <= n; j ++)
{
if(n%j == 0)//先找到它的因数(最小质因数)
{
while(n%j == 0)
{
n = n/j;//继续分解j之外的另一个因数 
tot ++;//计数 


}
printf("%d\n",tot);
}
return 0;
}

1 0