Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Prime Factorization code using recursion && Find number of divisor of a number.
- #include<iostream>
- #include<stdio.h>
- #include<math.h>
- #include<string.h>
- using namespace std;
- typedef long long lg;
- lg a,mul=1,add=1;
- lg arr[1000000];
- lg i=2,j=0;
- void prime_fctr(int n)
- {
- if(n!=1) ///lg w=a/2;
- {
- if(n%i==0)
- {
- arr[j]=i;
- j++;
- n=n/i;
- prime_fctr(n);
- }
- else
- {
- i++;
- prime_fctr(n);
- }
- }
- }
- int calculate_divisor()
- {
- for(int k=0; k<j; k++)
- {
- if(arr[k] == arr[k+1])
- {
- add++;
- }
- else
- {
- add++;
- mul*=add;
- add=1;
- }
- }
- return mul;
- }
- void print_fctr()
- {
- for(int k=0; k<j; k++)
- {
- cout<<arr[k]<<" ";
- }
- cout<<endl;
- }
- int main()
- {
- memset(arr,0,sizeof(arr));
- cin>>a;
- prime_fctr(a);
- print_fctr();
- cout<<calculate_divisor()<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement