Advertisement
Falak_Ahmed_Shakib

prime factors

Apr 5th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1.  
  2. // C++ program to print all prime factors
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. // A function to print all prime
  7. // factors of a given number n
  8. int primeFactors(int n)
  9. {
  10.  
  11. int cnt=0;
  12. // Print the number of 2s that divide n
  13. while (n % 2 == 0)
  14. {
  15. //cout << 2 << " ";
  16. cnt++;
  17. n = n/2;
  18. }
  19.  
  20. // n must be odd at this point. So we can skip
  21. // one element (Note i = i +2)
  22. for (int i = 3; i <= sqrt(n); i = i + 2)
  23. {
  24. // While i divides n, print i and divide n
  25. while (n % i == 0)
  26. {
  27. cnt++;
  28. // cout << i << " ";
  29. n = n/i;
  30. }
  31. }
  32.  
  33. // This condition is to handle the case when n
  34. // is a prime number greater than 2
  35. if (n > 2)cnt++;
  36. // cout << n << " ";
  37. return cnt;
  38. }
  39.  
  40. /* Driver code */
  41. int main()
  42. {
  43.  
  44. int t;
  45.  
  46. cin>>t;
  47.  
  48. while(t--)
  49. {
  50.  
  51.  
  52. int n,k;
  53. cin>>n>>k;
  54.  
  55. int cnt= primeFactors(n);
  56.  
  57. if(k<=cnt)cout<<1<<endl;
  58. else cout<<0<<endl;
  59.  
  60.  
  61.  
  62. }
  63. }
  64.  
  65. // This is code is contributed by rathbhupendra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement