Tasks Details
  
    
    
      
        
           
        
          
        
       
      
        
          
          
          
          
            
              
                
        
        
          
  
    
      
    
      
    
  
                        
 
                      
                        
  
  
  
                        
 
                      
                        
  
  
  
                        
 
                      
                        
  
  
  
                        
 
                      
                        
  
  
  
                        
  
    
    
      
        
          
        
        
    
      
      
          
            
              
              
            
             
              
                
                  
                  
              
             
           
        
      
       
    
  
          
            
          
        
       
    
   
 
                      
                        
  
  
  
                        
  
    
    
      
        
          
        
        
    
      
      
          
            
              
              
            
             
              
                
                  
                  
              
             
           
        
      
       
    
  
          
            
          
        
       
    
   
 
                      
                        
  
  
  
                        
 
                      
                        
  
  
  
                        
  
    
    
      
        
          
        
        
    
      
      
          
            
              
              
            
             
              
                
                  
                  
              
             
           
        
      
       
    
  
          
            
          
        
       
    
   
 
                      
                        
  
  
  
                        
  
    
    
      
        
          
        
        
    
       
    
  
          
            
          
        
       
    
   
 
                      
                        
  
  
  
                        
  
    
    
      
        
          
        
        
    
       
    
  
          
            
          
        
       
    
   
 
                      
                        
  
  
  
                        
  
    
    
      
        
          
            
        
    
  
  
  
    
       
    
      
      
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
        
          
            
              
              
            
             
              
             
           
        
      
       
    
      
      
          
          
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
          
          
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
          
          
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
          
          
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
        
          
          
        
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
          
            
              
              
            
             
              
             
           
        
      
       
    
  
          
            
          
        
       
    
   
 
                      
                    
                  
                
              
            
          
          
        
      
    
  
    
          easy
        
        
            1.
            
              CountFactors
            
          
          
            Count factors of given number n.
          
        
  
    
    Task Score
    
    
  
  
    
      
        
          
            
        
      
    
  
          
              57%
            
          
  
    
    Correctness
    
    
  
  
    
      
        
          
            
        
      
    
  
          
              100%
            
          
  
    
    Performance
    
    
  
  
    
      
        
          
            
        
      
    
  
        
              0%
            
          A positive integer D is a factor of a positive integer N if there exists an integer M such that N = D * M.
For example, 6 is a factor of 24, because M = 4 satisfies the above condition (24 = 6 * 4).
Write a function:
def solution(N)
that, given a positive integer N, returns the number of its factors.
For example, given N = 24, the function should return 8, because 24 has 8 factors, namely 1, 2, 3, 4, 6, 8, 12, 24. There are no other factors of 24.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..2,147,483,647].
 
Copyright 2009–2025 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.
              
            
          
            Solution
            
            
              
                
              
            
          
          
          
            
              Programming language used Python
            
          
          
            
            
              Time spent on task 3 minutes
              
            
            
          
          
          
            
              
                
                  Notes
                  
                    
                  
                
               
              
                
              
              
                
                  
                    
                  
                  
                  
                  
                  
                    
                  
                  
                    
                      
                        
  
  
                      
                        
                          not defined yet
                        
                      
                      
                    
                    
                  
        Code: 06:50:47 UTC,
        
          java,
        
        
          autosave 
        
      
      
      
      
    
          Analysis 
          
            
          
        
        
          
  
  
  
        
          expand all 
        
        Example tests
      
      
        
        
                1.
              
              
              
                
                  0.056 s
                
              
              
              
                
                  RUNTIME ERROR,
                  tested program terminated with exit code 1
                
                
              
            
                    
                      stderr:
                      
                Invalid result type, int expected, <class 'NoneType'> found.stdout:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
          Analysis 
          
            
          
        
        
          
  
  
  
        
          expand all 
        
        Example tests
      
      
        
        
                1.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  RUNTIME ERROR,
                  tested program terminated with exit code 1
                
                
              
            
                    
                      stderr:
                      
                Invalid result type, int expected, <class 'NoneType'> found.
          Analysis 
          
            
          
        
        
          
  
  
  
        
          expand all 
        
        Example tests
      
      
        
        
                1.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  RUNTIME ERROR,
                  tested program terminated with exit code 1
                
                
              
            
                    
                      stderr:
                      
                Invalid result type, int expected, <class 'NoneType'> found.stdout:
1 2 3 4 6 8 12 24
          Analysis 
          
            
          
        
        
          
  
  
  
          Analysis 
          
            
          
        
        
          
  
  
  Analysis summary
            
  The following issues have been detected: timeout errors.
For example, for the input 1948102 the solution exceeded the time limit.
          Analysis 
          
            
          
        
        
          
  
    
      Detected time complexity:
        
          O(N)
        
        
      
        
          expand all 
        
        Correctness tests
      
      
        
        
                1.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                2.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                1.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                2.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                3.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                4.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                5.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                6.
              
              
              
                
                  0.040 s
                
              
              
              
                
                  OK
                
                
              
            
                7.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                8.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                9.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                10.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                1.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                2.
              
              
              
                
                  0.040 s
                
              
              
              
                
                  OK
                
                
              
            
                1.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                2.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                3.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                1.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                2.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                1.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                2.
              
              
              
                
                  0.036 s
                
              
              
              
                
                  OK
                
                
              
            
                1.
              
              
              
                
                  0.044 s
                
              
              
              
                
                  OK
                
                
              
            
                2.
              
              
              
                
                  0.040 s
                
              
              
              
                
                  OK
                
                
              
            
                1.
              
              
              
                
                  0.040 s
                
              
              
              
                
                  OK
                
                
              
            
        
          expand all 
        
        Performance tests
      
      
        
            medium1
            
              
N=362,880=9!, N=1,948,102
          
            N=362,880=9!, N=1,948,102
✘
 
          
          
            TIMEOUT ERROR
            
              
                
running time: 0.224 sec., time limit: 0.144 sec.
        running time: 0.224 sec., time limit: 0.144 sec.
                1.
              
              
              
                
                  0.064 s
                
              
              
              
                
                  OK
                
                
              
            
                2.
              
              
              
                
                  0.224 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  running time: 0.224 sec., time limit: 0.144 sec.
                
                
              
            
            medium2
            
              
N=3,628,800=10!, N=5,621,892, N=4,999,696
          
            N=3,628,800=10!, N=5,621,892, N=4,999,696
✘
 
          
          
            TIMEOUT ERROR
            
              
                
running time: 0.272 sec., time limit: 0.160 sec.
        running time: 0.272 sec., time limit: 0.160 sec.
                1.
              
              
              
                
                  0.272 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  running time: 0.272 sec., time limit: 0.160 sec.
                
                
              
            
                2.
              
              
              
                
                  0.408 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  running time: 0.408 sec., time limit: 0.160 sec.
                
                
              
            
                3.
              
              
              
                
                  0.368 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  running time: 0.368 sec., time limit: 0.160 sec.
                
                
              
            
            big1
            
              
N=27,043,111, N=39,916,800=11!, N = 39,992,976
          
            N=27,043,111, N=39,916,800=11!, N = 39,992,976
✘
 
          
          
            TIMEOUT ERROR
            
              
                
running time: 1.816 sec., time limit: 0.160 sec.
        running time: 1.816 sec., time limit: 0.160 sec.
                1.
              
              
              
                
                  1.816 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  running time: 1.816 sec., time limit: 0.160 sec.
                
                
              
            
                2.
              
              
              
                
                  2.612 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  running time: 2.612 sec., time limit: 0.160 sec.
                
                
              
            
                3.
              
              
              
                
                  2.668 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  running time: 2.668 sec., time limit: 0.160 sec.
                
                
              
            
                1.
              
              
              
                
                  6.000 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  Killed. Hard limit reached: 6.000 sec.
                
                
              
            
                2.
              
              
              
                
                  6.000 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  Killed. Hard limit reached: 6.000 sec.
                
                
              
            
            big3
            
              
N=479,001,600=12!, N=780291637(prime), N=449,991,369
          
            N=479,001,600=12!, N=780291637(prime), N=449,991,369
✘
 
          
          
            TIMEOUT ERROR
            
              
                
Killed. Hard limit reached: 6.000 sec.
        Killed. Hard limit reached: 6.000 sec.
                1.
              
              
              
                
                  6.000 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  Killed. Hard limit reached: 6.000 sec.
                
                
              
            
                2.
              
              
              
                
                  6.000 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  Killed. Hard limit reached: 6.000 sec.
                
                
              
            
                3.
              
              
              
                
                  6.000 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  Killed. Hard limit reached: 6.000 sec.
                
                
              
            
            extreme_maxint
            
              
N=1,000,000,000, N=MAX_INT, N=2147,395,600
          
            N=1,000,000,000, N=MAX_INT, N=2147,395,600
✘
 
          
          
            TIMEOUT ERROR
            
              
                
Killed. Hard limit reached: 6.000 sec.
        Killed. Hard limit reached: 6.000 sec.
                1.
              
              
              
                
                  6.000 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  Killed. Hard limit reached: 6.000 sec.
                
                
              
            
                2.
              
              
              
                
                  6.000 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  Killed. Hard limit reached: 6.000 sec.
                
                
              
            
                3.
              
              
              
                
                  6.000 s
                
              
              
              
                
                  TIMEOUT ERROR,
                  Killed. Hard limit reached: 6.000 sec.