Project Euler #179: Consecutive positive divisors

Sort by

recency

|

61 Discussions

|

  • + 0 comments

    C solution based on an idea from this blog. For some reason, the same idea failed on C++ due to timeout.

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    
    int main() {
        
        unsigned t;
        scanf("%u", &t);
        
        // divisors sieve
        unsigned N = 1e7;
        unsigned *sieve, *pref_sum;
        sieve = (unsigned *) calloc(N + 1, sizeof(unsigned));
        pref_sum = (unsigned *) calloc(N + 1, sizeof(unsigned));
        
        for(unsigned i = 1; i <= N; ++i)
            for(unsigned j = i; j <= N; j += i)
                ++sieve[j];
        
        for(unsigned i = 3; i <= N; ++i)
            pref_sum[i] = pref_sum[i - 1] + (sieve[i] == sieve[i - 1]);
        
        for(unsigned i = 0; i < t; ++i) {
            unsigned k;
            scanf("%u", &k);
            
            printf("%u\n", pref_sum[k]);
        }
        
        free(sieve);
         
        return 0;
    }
    
  • + 0 comments

    Can anybody tell me what I'm missing?

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    t = int(input().rstrip())
    nums = [0]*(10**6)
    col = [0]*(10**6)
    max_nums = 1
    nums[0] = 1
    
    def enlarge_max(next_max):
        global max_nums
        global nums
        global col
        
        #nums[0] = 1
        #print("enlarging from {} to {}".format(max_nums, next_max))
        for i in range(1, next_max+1):
            ss = int(max_nums / i) * i
            #if ss == max_nums:
            #    nums[ss-1] += 1
            ss += i
            #print("... i={} starting ss={}".format(i, ss))
            while ss <= next_max:
                #print("   cur ss={}".format(ss))
                nums[ss-1] += 1
                ss += i
                
        #print("cur nums={}".format(nums[0:next_max]))
        #print("new max = {}".format(next_max))
        prev_col = col[max_nums-1]
        #print("    prev max = {} prev_col = {}".format(max_nums, prev_col))
        
                
        for i in range(max_nums, next_max):
            #col[i-1] = prev_col
            
            if nums[i] == nums[i+1]:
                #print("  found equality at i={} {}={}".format(i, nums[i], nums[i+1]))
                prev_col += 1
            col[i] = prev_col
        
        #print(" arr equality={}".format(col[0:next_max]))
                
                
        max_nums = next_max
            
    for _ in range(0, t):
        k = int(input().rstrip())
        enlarge_max(k)
        print("{}".format(col[k-1]))
    
  • + 0 comments

    What is actully n? explaination is too short to understand the output. The only n < 15 are 2 and 14.

  • + 0 comments

    Can anyone tell me what am I missing?? I am able to pass test case 0 not rest of them . Please help thank you

    con <- file("stdin", open = "r")
    data <- as.numeric(readLines(con))
    
    for (i in 1:data[1]){
        I <- data[i+1]
        n <- array(0,dim = I)
    for (i in 1:floor((I-1)/2)){
      for (j in seq(i*2,I, by = i)){
        n[j]= n[j]+1
      } 
     }
     b <- 0
     for(i in 2:I){
      if((n[i]==n[i-1])==TRUE){
        b <- b+1
      }
     }
         cat(b,sep = "\n")
    }
    
  • + 2 comments

    what the question mean i cant understand please anyone can explain the question