Skip to main content
Commonmark migration
Source Link

#C, 110 bytes

C, 110 bytes

p;s;i;j;f(n){j=0;while(n){i=++j;p=1;s=0;do p*=i%10,s+=i%10;while((i/=10)>0);if(p>0&&j%p+j%s==0)--n;}return j;}

Ungolfed and usage:

p;s;i;j;
f(n){
 j=0;
 while(n){
  i=++j;
  p=1;
  s=0;
  do
   p*=i%10,   //product
   s+=i%10;   //sum
  while((i/=10)>0);
  //check if product is not zero since floating point exception
  if(p>0 && j%p + j%s == 0)--n;
 }
 return j;
}

int main(){
 int n;
 scanf("%d",&n);
 printf("\n%d\n", f(n));
}

#C, 110 bytes

p;s;i;j;f(n){j=0;while(n){i=++j;p=1;s=0;do p*=i%10,s+=i%10;while((i/=10)>0);if(p>0&&j%p+j%s==0)--n;}return j;}

Ungolfed and usage:

p;s;i;j;
f(n){
 j=0;
 while(n){
  i=++j;
  p=1;
  s=0;
  do
   p*=i%10,   //product
   s+=i%10;   //sum
  while((i/=10)>0);
  //check if product is not zero since floating point exception
  if(p>0 && j%p + j%s == 0)--n;
 }
 return j;
}

int main(){
 int n;
 scanf("%d",&n);
 printf("\n%d\n", f(n));
}

C, 110 bytes

p;s;i;j;f(n){j=0;while(n){i=++j;p=1;s=0;do p*=i%10,s+=i%10;while((i/=10)>0);if(p>0&&j%p+j%s==0)--n;}return j;}

Ungolfed and usage:

p;s;i;j;
f(n){
 j=0;
 while(n){
  i=++j;
  p=1;
  s=0;
  do
   p*=i%10,   //product
   s+=i%10;   //sum
  while((i/=10)>0);
  //check if product is not zero since floating point exception
  if(p>0 && j%p + j%s == 0)--n;
 }
 return j;
}

int main(){
 int n;
 scanf("%d",&n);
 printf("\n%d\n", f(n));
}
Source Link
Karl Napf
  • 4.4k
  • 13
  • 31

#C, 110 bytes

p;s;i;j;f(n){j=0;while(n){i=++j;p=1;s=0;do p*=i%10,s+=i%10;while((i/=10)>0);if(p>0&&j%p+j%s==0)--n;}return j;}

Ungolfed and usage:

p;s;i;j;
f(n){
 j=0;
 while(n){
  i=++j;
  p=1;
  s=0;
  do
   p*=i%10,   //product
   s+=i%10;   //sum
  while((i/=10)>0);
  //check if product is not zero since floating point exception
  if(p>0 && j%p + j%s == 0)--n;
 }
 return j;
}

int main(){
 int n;
 scanf("%d",&n);
 printf("\n%d\n", f(n));
}