Advertisement
hemel18681

Number of Divisor of a Number using Prime Factorization

Feb 5th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define max_num 1000007
  3. using namespace std;
  4. int marking[1000007+5];
  5. vector<int> storage;
  6. void prime_number(){
  7. for(int i=2;i<=max_num;i++){
  8. if(marking[i]==0){
  9. for(int j=i+i;j<=max_num;j=j+i){
  10. marking[j]=1;
  11. }
  12. }
  13. }
  14. for(int i=2;i<=max_num;i++){
  15. if(marking[i]==0){
  16. storage.push_back(i);
  17. }
  18. }
  19. sort(storage.begin(),storage.end());
  20. }
  21. int main()
  22. {
  23. prime_number();
  24. int test_case,case_no=0;
  25. scanf("%d",&test_case);
  26. while(test_case--){
  27. long long number; cin>>number;
  28. int counting,total=1;
  29. for(int i=0;i<storage.size() and storage[i]<=sqrt(number);i++){
  30. counting=0;
  31. if(number<storage[i]) break;
  32. while(number%storage[i]==0){
  33. number=number/storage[i];
  34. counting++;
  35. }
  36. total=total*(counting+1);
  37. }
  38. if(number>1) total=total*2;
  39. printf("Case %d: %d\n",++case_no,total-1);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement