Number of factors | Practice | GeeksforGeeks

Find the number of factors for a given integer N.
 
Example 1:
Input:
N = 5
Output:
2
Explanation:
5 has 2 factors 1 and 5
Example 2:
Input:
N = 25
Output:
3
Explanation:
25 has 3 factors 1, 5, 25


Your Task:
You don't need to read input or print anything. Your task is to complete the function countFactors() which takes an integer N as input parameters and returns an integer, total number factor of N.
 
Expected Time Complexity: O(sqrt(N))
Expected Space Complexity: O(1)
 
Constraints:
1 <= N <= 100000
0
Shreyansh Kumar Singh10 months ago
Shreyansh Kumar Singh
Python Solution: Counting Divisors
def countFactors (self, N):    DiViSoRs = 0;    sqrtN = int(sqrt(N))+1;    for factor in range(1,sqrtN):        if N%factor == 0:            if N/factor == factor:                DiViSoRs += 1;            else:                DiViSoRs += 2;    return DiViSoRs;
0
62 vishal meena11 months ago
62 vishal meena
int sum=0;       for(int i=1;i<=N;i++)       {           if(N%i==0)           {               sum++;           }       }       return sum;    }
+2
Vaidhyanathan S M2 years ago
Vaidhyanathan S M
int countFactors(int N){        //code here        int count=0;        for(int i=1;i<=sqrt(N);i++)        {            if(N%i==0)            {                if(N/i==i)                    count++;                else count+=2;                }        }        return count;    }
0
Suraj Chhabria2 years ago
Suraj Chhabria
T = int(input())
while T:    a = int(input())    l = [i for i in range(1,a+1) if (a%i == 0)]
    print(len(l))
    T-=1
0
Raghav Nibandhe2 years ago
Raghav Nibandhe
factors_of = int(input('enter the number:'))numberof_factors = []for factors_of in range(1, factors_of+1):    if factors_of%2==0:        numberof_factors.append(factors_of)print(len(numberof_factors))
0
Boppudi Swathi2 years ago
Boppudi Swathi
for _ in range(int(input())):    n=int(input())    count=0    for i in range(1,n+1):        if(n%i==0):            count+=1    print(count)
0
Yugansh Dhir2 years ago
Yugansh Dhir
0.13 SECOND CODE
/*package whatever //do not write package name here */import java.util.*;import java.lang.*;import java.io.*;class GFG {public static void main (String[] args) {//codeScanner sc = new Scanner(System.in);        int t = sc.nextInt();        while(t-- >0){            int n = sc.nextInt();            int result = 0;            for(int i= 1; i<=n; i++){                if(n%i ==0){                    result+= 1;                }            }System.out.println(result);         }}}
0
Varin Kala2 years ago
Varin Kala
When I click on submit, it shows an error that code does not work for multiple cases, eg. 32.But when I enter 32 as custom input, it gives the correct answer. Plz Help!Code:#include <iostream>using namespace std;
int main() {int t;cin >> t;int n[t];for (int i = 0; i < t; i++){    int ctr = 0;    cin >> n[i];    for (int j = 1; j <= n[i]; j++)    {       if (n[i] % j == 0)          ctr++;    }    cout << ctr;}return 0;}
0
Aman Chauhan3 years ago
Aman Chauhan
what is floating point error
0
Kirti Agrawal3 years ago
Kirti Agrawal
please have a look my code
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.