This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class UnfriendlyNumbers { | |
| private static long gcd(long a, long b){ | |
| if(b==0) return a; | |
| else return gcd(b,a%b); | |
| } | |
| public static long calc(long[]arr, long k){ | |
| HashSet<Long> hs= new HashSet<Long>(); | |
| for(int i=0;i<arr.length;i++){ | |
| hs.add(gcd(arr[i],k)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SumSquareDiff { | |
| public static long calculate(int n){ | |
| int sum_of_sq=0; | |
| int sum=0; | |
| for(int i=1;i<=n;i++){ | |
| sum+=i; | |
| sum_of_sq+=i*i; | |
| } | |
| return sum*sum-sum_of_sq; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class LargestProductOf_m_ConsecutiveDigits { | |
| public static int calculate(String s,int m) throws Exception{ | |
| int max=0; | |
| for(int i=0;i<=s.length()-m;i++){ | |
| int prod=getProd(s, i, m); | |
| if(prod>max) max=prod; | |
| } | |
| return max; | |
| } | |
| private static int getProd(String s, int i,int m) throws Exception{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SumOfPrimes { | |
| public static long calculate(int n){ | |
| long sum=2; | |
| for(int i=3;i<n;i++) | |
| if(isPrime(i)) | |
| sum+=i; | |
| return sum; | |
| } | |
| private static boolean isPrime(int p){ | |
| for(int i=2;i<=Math.sqrt(p);i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SpecialPythagoreanTripletProd { | |
| public static int calculate(int n){ | |
| for(int a=2;a<n;a++){ | |
| if((n*n-2*n*a)%(2*n-2*a)==0){ | |
| int b=(n*n-2*n*a)/(2*n-2*a); | |
| int ret= a*b*(n-a-b); | |
| if(ret>0) return ret; | |
| } | |
| } | |
| return 0;//no Triplet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class StringSimilarity { | |
| public static int calculate(String s){ | |
| char[]arr=s.toCharArray(); | |
| int length=arr.length; | |
| int count=length; | |
| for(int i=1;i<length;i++){ | |
| int len=length-i; | |
| int j=0; | |
| for(;j<len;j++) | |
| if(arr[j]!=arr[j+i]){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class UtopianIdentificationNumber { | |
| public static boolean test(String s){ | |
| int stage=1; | |
| int count=0; | |
| for(int i=0;i<s.length();i++){ | |
| char c= s.charAt(i); | |
| if(stage==1){ | |
| if(!(c>='a' && c<='z')){ | |
| if((i-count)>=0 && (i-count)<=3){ | |
| count=i; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class SplittingCandies { | |
| public static long getStudentCandies(long N, long K){ | |
| if(K==0) return 0; | |
| return N/K; | |
| } | |
| public static long getTeacherCandies(long N, long K){ | |
| if(K==0) return N; | |
| return N%K; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class HelloHello { | |
| private class Plan{ | |
| int activation; | |
| double rates; | |
| int planNo; | |
| int minsPerMonths; | |
| int months; | |
| public Plan(int planNo,int activation,double rates,int minsPerMonths,int months){ | |
| this.planNo=planNo; |