Project Euler #3: Largest prime factor

Sort by

recency

|

473 Discussions

|

  • + 0 comments

    Below is my code but one hidden test case is still failing, can someone help here?

    import java.util.*;

    public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int a = 0; a < t; a++){
            long n = sc.nextLong();
            boolean isPrime=checkPrime(n);
            if(!isPrime){
                HighestPrimeFactors(n);}
            else
            {System.out.println(n);}
        }
        sc.close();
    }
     public static boolean checkPrime(long num){
    int count=0;
    for(long i=1;i<=num;i++){
            if(num%i==0){    
             count++; 
            }            
        }
     if(count==2)    
     return true;
     else
     return false;   
    }
    
    public static void HighestPrimeFactors(long n){ 
        long max=0;   
        for(long i=1;i<n;i++){
            if(n%i==0){               
             if(checkPrime(i)==true && max<i){
                max=i;
             }
            }
        }
     System.out.println(max);   
    }
    

    }

  • + 0 comments

    i passed 3 test cases but failed to pass last 2 test case.Can anybody help me out?

    handle,"%d",a0 = 0; t; Extra open brace or missing close bracehandle,"%ld",prime=array(); for(i<=i++){ if(i==0){ array_push(i); } } prime as Extra close brace or missing open braceparr)); echo "\n"; }

    ?>****

  • + 0 comments
    for a0 in range(t):
        n = int(input().strip())
        
        i = 2
        while i*i <= n:
            if n%i == 0:
                n //= i
            else:
                i += 1
        print(n)
    
  • + 0 comments

    below code in python passed 1st sample test case but failed hidden test case, could anyone help:

    mport sys def factor(n): l=[] for i in range(2,n+1): if n%i==0: l.append(i) for j in l: for k in range(2, j): if (j % k) != 0: continue else: l.remove(j) break #print(j,k) #print(l) l.sort(reverse=True) return(l[0])

    t = int(input().strip()) for a0 in range(t): n = int(input().strip()) print(factor(n))

  • + 2 comments

    why my code isnt passing more than 1 case import sys t = int(input().strip()) for a0 in range(t): n = int(input().strip())

    l = []
    for i in range(2, n):
        if n%i==0:
            l.append(i)
    if l:
        print(l[-1])
    else:
        print(n)