forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifiedKaprekarNumbers.java
More file actions
34 lines (33 loc) · 860 Bytes
/
ModifiedKaprekarNumbers.java
File metadata and controls
34 lines (33 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Scanner;
public class Solution {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
long p = sc.nextInt();
long q = sc.nextInt();
long c = 0;
for(long i=p;i<=q;i++){
long num = i;
long d = 0;
while(num!=0){
num/=10;
d++;
}
long n = (long)Math.pow(i,2);
long k = n;
long d1 = 0;
while(k!=0){
k = k/10;
d1++;
}
long r,l;
r = n%(long)(Math.pow(10,d));
l = n/(long)(Math.pow(10,d));
if(l+r==i){
System.out.print(i + " ");
c++;
}
}
if(c==0)
System.out.println("INVALID RANGE");
}
}