Project Euler #153: Investigating Gaussian Integers

  • + 1 comment

    i think my logic is right..just it is taking more time...please someone help :( .............................. import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;

    public class Solution {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long n=sc.nextInt();
        long sum=0;
        for(long ni=1;ni<=n;ni++)
            {
            for(long a=1;a<=ni;a++)
                {
                for(long b=0;b<ni;b++)
                    {
                    long den1=a*a+b*b,num_a=ni*a,num_b=ni*b;
                    if((num_a%den1==0)&(num_b%den1==0)&(b!=0))
                        sum=sum+2*a;
                    if((num_a%den1==0)&(num_b%den1==0)&(b==0))
                        sum=sum+a;
    
                }
            }
        }
        System.out.println(sum);
    }
    

    }