We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #153: Investigating Gaussian Integers
You are viewing a single comment's thread. Return to all comments →
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 {
}