Project Euler #108: Diophantine reciprocals I

Sort by

recency

|

12 Discussions

|

  • + 0 comments
    import math
    
    def num_square_divisors(n):
        result = 1
        reduce = n
        divisor = 2
        
        while divisor * divisor <= reduce:
            exponent = 0
            while reduce % divisor == 0:
                exponent += 1
                reduce //= divisor
            result *= 2 * exponent + 1
            divisor += 1 if divisor == 2 else 2
    
        if reduce > 1:
            result *= 3 
    
        return result
    
    def main():
        import sys
        input = sys.stdin.read
        data = input().split()
        tests = int(data[0])
        results = []
        
        for i in range(1, tests + 1):
            n = int(data[i])
            divisors = num_square_divisors(n)
            half = (divisors + 1) // 2
            results.append(half)
        
        for result in results:
            print(result)
    
    // What's wrong with my code, It passes 7 testcases only.. and throw Timeout error?? Anyone please help
    
    if __name__ == "__main__":
        main()
    
  • + 0 comments

    they should provide with more examples or atleast show the inputs that are giving time out ):

  • + 0 comments
    int i,j,k,t;
        scanf("%d",&k);
        int num[k];
        if(k<=100&&k>=1)
        for(i=0;i<k;i++)
        {scanf("%d",&num[i]);}
        for(i=0;i<k;i++){j=0;
         if(num[i]>(int)pow(10,18)&&num[i]<2){continue;}
        for(t=1;t<=num[i];t++){
          if(((int)pow(num[i],2))%t==0){
            j+=1;
          }else{continue;}
        }printf("%d\n",j);
        }
    

    I am able to pass only four test cases(0,1,2,3) for (4,5,6) testcases it saya wrong answer and for the rest it says timeout. what's the mistake i have done.please correct me.

  • + 0 comments

    i am getting a Terminated due to timeout for testcases#7to#11 plzzz someone can clarify with the problem !!!

  • + 0 comments

    I got the logic but there is a timeout after 6th test case. Not able to shorten the code anymore .