Rkhamim

Untitled

Oct 18th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using u64 = uint64_t;
  4. u64 binpower(u64 base, u64 e, u64 mod) {
  5. u64 result = 1;
  6. base %= mod;
  7. while (e) {
  8. if (e & 1)
  9. result = (u64)result * base % mod;
  10. base = (u64)base * base % mod;
  11. e >>= 1;
  12. }
  13. return result;
  14. }
  15. bool check_composite(u64 n, u64 a, u64 d, int s) {
  16. u64 x = binpower(a, d, n);
  17. if (x == 1 || x == n - 1)
  18. return false;
  19. for (int r = 1; r < s; r++) {
  20. x = (u64)x * x % n;
  21. if (x == n - 1)
  22. return false;
  23. }
  24. return true;
  25. };
  26. bool MillerRabin(u64 n) { // returns true if n is probably prime, else returns false.
  27. if (n < 4)
  28. return n == 2 || n == 3;
  29. int s = 0;
  30. u64 d = n - 1;
  31. while ((d & 1) == 0) {
  32. d >>= 1;
  33. s++;
  34. }
  35. for (int a:{2, 3, 5, 7, 11, 13, 17, 19, 23,29,31,37}) {
  36. if(n==(u64)a)return true;
  37. if (check_composite(n, a, d, s))
  38. return false;
  39. }
  40. return true;
  41. }
  42. long long int count_divisor(long long int n)
  43. {
  44. long long int div=1,x=n;
  45. for(long long int i=2;i*i*i<=x;i++)
  46. {
  47. long long int j=1;
  48. while(n%i==0)
  49. {
  50. j++;
  51. n/=i;
  52. }
  53. div*=j;
  54. }
  55. long long int p=sqrt(n);
  56. if(n==1)div*=1;
  57. else if(MillerRabin(n))div*=2;
  58. else if(p*p==n)div*=3;
  59. else div*=4;
  60. return div;
  61. }
  62. int main()
  63. {
  64. long long int t,n,m,x,y,z,i,j,k;
  65. scanf("%lld",&t);
  66. while(t--)
  67. {
  68. scanf("%lld",&n);
  69. cout<<count_divisor(n)<<endl;
  70. }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment