Rkhamim

Untitled

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