fork download
  1. /*------- OPTIMIZE -------*/
  2. #pragma GCC optimize("Ofast")
  3. #pragma GCC optimize("O2")
  4.  
  5. /*------- INCLUDE -------*/
  6. #include<bits/stdc++.h>
  7.  
  8. /*------- MACROS -------*/
  9. #define int long long
  10. #define pb push_back
  11. #define fi first
  12. #define se second
  13. #define is insert
  14. #define _it ::iterator
  15. #define FOR(i,l,r,n) for((i)=(l);(i)<=(r);(i)+=(n))
  16. #define FOD(i,r,l,n) for((i)=(r);(i)>=(l);(i)-=(n))
  17. #define lowerbound(v,x) lower_bound((v).begin(),(v).end(),(x))
  18. #define upperbound(v,x) upper_bound((v).begin(),(v).end(),(x))
  19. #define all(v) (v).begin(),(v).end()
  20. using namespace std;
  21.  
  22. /*------- CONSTANT -------*/
  23. const double pi=3.141592653589;
  24. const int mod=1e9+7;
  25. const int llm=LONG_LONG_MAX;
  26.  
  27. /*--- SOLVING FUNCTIONS ---*/
  28. int f[1000001]={},uoc; vector<int> v;
  29. void sangnto(int n) //sang nguyen to, tao mang chi gom cac so nguyen to
  30. {
  31. int i,j;
  32. FOR(i,2,sqrt(n),1)
  33. {
  34. if (f[i]==0) {FOR(j,i,n/i,1) f[i*j]=1;}
  35. }
  36. v.pb(2);
  37. FOR(i,3,n,2) {if (f[i]==0) v.pb(i);}
  38. }
  39. void demuoc(int x) //dem uoc bang phan tich thua so nguyen to + mang nguyen to
  40. { uoc=1;
  41. if (x==1) {cout<<1<<endl; return;}
  42. if (f[x]==0) {cout<<2<<endl; return;}
  43. int i,d,x1=x;
  44. FOR(i,0,v.size()-1,1)
  45. { d=0;
  46. if (v[i]>sqrt(x1)||x==1) break;
  47. if (x%v[i]==0)
  48. {
  49. while (x%v[i]==0) {x=x/v[i]; d++;}
  50. }
  51. uoc=uoc*(d+1);
  52. }
  53. if (x!=1) uoc=uoc*2;
  54. cout<<uoc<<endl;
  55. }
  56. void run()
  57. {
  58. int n,x,i;
  59. cin>>n; sangnto(1000000);
  60. FOR(i,1,n,1)
  61. {
  62. cin>>x; demuoc(x);
  63. }
  64. }
  65.  
  66. /*--------- MAIN ---------*/
  67. signed main()
  68. {
  69. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  70. // freopen(" .inp","r",stdin);
  71. // freopen(" .out","w",stdout);
  72.  
  73. run();
  74. return 0;
  75. }
Success #stdin #stdout 0.01s 12040KB
stdin
3
16
17
18
stdout
5
2
6