Sie sind auf Seite 1von 2

#include<stdio.

h>
#include<math.h>

int sumofdig(int n)
{
int s_d=0;
while(n)
{
s_d = s_d+n%10;
n=n/10;
}
return s_d;
}

int num_base(int n,int b)


{
int n_b=0,q,r,i=0;
while(n>1)
{
q = n/b;
r = n%b;
n_b = n_b+r*pow(10,i);
n = q;
i=i+1;
}
n_b = n_b+q*pow(10,i);
return n_b;
}

int isdivisible(int n_b,int s_d_b,int b)


{
int is_divisible,n_b_10=0,s_d_b_10=0,i=0;
while(n_b>1)
{
n_b_10 = n_b_10+(n_b%10)*pow(b,i);
s_d_b_10 = s_d_b_10+(s_d_b%10)*pow(b,i);
n_b=n_b/10;
s_d_b=s_d_b/10;
i=i+1;
}
n_b_10 = n_b_10+n_b*pow(b,i);
if (s_d_b==1)
s_d_b_10 = s_d_b_10+s_d_b*pow(b,i);
if(n_b_10%s_d_b_10==0)
is_divisible = 1;
else
is_divisible = 0;
return is_divisible;
}

int main()
{
int b,T,L,i,j,n_b,s_d,s_d_b,n_b_L,s_d_L,s_d_b_L;
int found = 0,temp_bool;
printf("Enter b and T: \n");
scanf("%d %d",&b,&T);
int n=b;
while(found == 0)
{
n_b = num_base(n,b);
s_d = sumofdig(n_b);
s_d_b = num_base(s_d,b);
if(isdivisible(n_b,s_d_b,b)==1)
{
temp_bool = 1;
L = n;
for(i=0;i<T;i++)
{
n_b_L = num_base(L+i,b);
s_d_L = sumofdig(n_b_L);
s_d_b_L = num_base(s_d_L,b);
temp_bool = temp_bool && isdivisible(n_b_L,s_d_b_L,b);
if (temp_bool == 0)
break;
}
if (temp_bool==1)
{
if (!
(isdivisible(num_base(L+T,b),num_base(sumofdig(num_base(L+T,b)),b),b) ||
isdivisible(num_base(L-1,b),num_base(sumofdig(num_base(L-1,b)),b),b))==1)
{
printf("%d",n_b);
found = 1;
}
}
else
n=n+1;
}
else
n=n+1;
}
}

Das könnte Ihnen auch gefallen