Advertisement
galib71

///Prime Factorization code using recursion && Find number o

Jan 17th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. ///Prime Factorization code using recursion && Find number of divisor of a number.
  2. #include<iostream>
  3. #include<stdio.h>
  4. #include<math.h>
  5. #include<string.h>
  6. using namespace std;
  7. typedef long long lg;
  8. lg a,mul=1,add=1;
  9. lg arr[1000000];
  10. lg i=2,j=0;
  11. void prime_fctr(int n)
  12. {
  13. if(n!=1) ///lg w=a/2;
  14. {
  15. if(n%i==0)
  16. {
  17. arr[j]=i;
  18. j++;
  19. n=n/i;
  20. prime_fctr(n);
  21. }
  22. else
  23. {
  24. i++;
  25. prime_fctr(n);
  26. }
  27. }
  28. }
  29.  
  30. int calculate_divisor()
  31. {
  32. for(int k=0; k<j; k++)
  33. {
  34. if(arr[k] == arr[k+1])
  35. {
  36. add++;
  37. }
  38. else
  39. {
  40. add++;
  41. mul*=add;
  42. add=1;
  43. }
  44. }
  45. return mul;
  46. }
  47.  
  48. void print_fctr()
  49. {
  50. for(int k=0; k<j; k++)
  51. {
  52. cout<<arr[k]<<" ";
  53. }
  54. cout<<endl;
  55. }
  56.  
  57. int main()
  58. {
  59. memset(arr,0,sizeof(arr));
  60. cin>>a;
  61. prime_fctr(a);
  62. print_fctr();
  63. cout<<calculate_divisor()<<endl;
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement