in modified kaprekar number, say x
let number of digits in x, say nd
let square = x*x
then
x = square/10^nd + square%(10^nd) then x would be a modified kaprekar number
https://www.hackerrank.com/challenges/kaprekar-numbers/problem
#include<stdio.h>
#include<math.h>
int main()
{
long int n,m,r,f;
int flag = 0;
scanf("%ld%ld",&n,&m);
for(long int i=n;i<=m;i++)
{
long int sum;
long int a = log10(i)+1;
long int p = i * i;
long int g = pow(10,a);
sum = p%g + p/g;
if(sum == i)
{
printf("%ld ",sum);
flag++;
}
}
if(flag == 0)
printf("INVALID RANGE");
return 0;
}
No comments:
Post a Comment