CODE[VS] 3164 質因數分解
阿新 • • 發佈:2018-06-11
AC def tro esp efault color pri NPU 難度
題目描述 Description
(多數據)給出t個數,求出它的質因子個數。
數據沒坑,難度降低。
輸入描述 Input Description
第一行 t
之後t行 數據
輸出描述 Output Descriptiont行 分解後結果(質因子個數)
樣例輸入 Sample Input
2
11
6
樣例輸出 Sample Output1
2
數據範圍及提示 Data Size & Hint
(樣例解釋)11自己本身是一個質數,所以計入其中。
順便提示:t<=100000。每個數小於long long unsigned 呵呵
剛剛沒忍住,去看了丁丁當年好聲音的辛德瑞拉,太好聽了。
還有毛曉彤前陣子在跨界歌王上的辛德瑞拉,哇,沒想到沒想到哇。
加油,好好愛自己,不要理那些流言蜚語。
數學好題啊。
剛開始確實想到唯一分解定理了,
不過想cha pi了。
zz的想成要麽一個要麽兩個,質數一個,其他都倆了、、
哇塞,這樣居然還能過倆點。
下面看ac代碼:
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5#include<cstring> 6 using namespace std; 7 8 long long n,a,ans; 9 10 int main() 11 { 12 scanf("%lld",&n); 13 for(int i=1;i<=n;++i) 14 { 15 ans=0; 16 scanf("%lld",&a); 17 for(long long j=2;j<=sqrt(a);++j) 18 while(a%j==0) 19 { 20 a/=j; 21 ans++; 22 } 23 if(a!=1) ans++; 24 printf("%d\n",ans); 25 } 26 return 0; 27 }
CODE[VS] 3164 質因數分解