Advertisement
karbaev

ndivisors

Feb 29th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. int ndivisors(int n){
  7.     int res = 0, i=0;
  8.     cout<<1<<endl<<n<<endl;
  9.     for ( i=2; i*i<=n; i++)
  10.         if (n % i == 0){
  11.             res += 2; //подсчет количества делителей
  12.             if(i!=n/i)
  13.                 cout<<i<<endl<<n/i<<endl; //вывод всех делителей
  14.             else cout<<i<<endl;
  15.         }
  16.     return res +2 -(n==1) -((i-1)*(i-1)==n);
  17. }
  18.  
  19. int main(){
  20.     cout<<"Ndivisors="<<ndivisors(34);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement