您的位置:首页 > 其它

3164 质因数分解

2016-05-25 16:34 267 查看

3164 质因数分解

时间限制: 1 s

空间限制: 256000 KB

题目等级 : 黄金 Gold

题解

题目描述 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 呵呵

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;
int n;
long long x;
void solve(long long a)
{
int p=0;
for(long long i=2;i<=a;i++)
if(a%i==0)
while(a%i==0)
{
a=a/i;
p++;
}
printf("%d\n",p);

}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&x);
solve(x);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: