Skip to content

Instantly share code, notes, and snippets.

@krofna
Last active August 29, 2015 14:04
Show Gist options
  • Save krofna/b3b3f92a11bb0540dd96 to your computer and use it in GitHub Desktop.
Save krofna/b3b3f92a11bb0540dd96 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int mul_znam(char* A)
{
int b = A[0] - '0', i;
for (i = 1; A[i]; ++i)
if (A[i] != '0')
b *= A[i] - '0';
return b;
}
int produzetak(char* A)
{
int a = atoi(A), i = 0;
if (a == 0)
return 0;
return a + mul_znam(A);
}
int slijedeci(char* A, char* B)
{
return produzetak(A) + produzetak(B);
}
int produzetak_prethodnog(char* B, int C)
{
return C - atoi(B) - mul_znam(B);
}
void prethodni(char* B, char* C)
{
int c = atoi(C);
int k = produzetak_prethodnog(B, c), i;
/* Prethodni broj je striktno manji od svog produzetka */
/* Moguce je jos preciznije odrediti granice al mi se neda */
for (i = 0; i < k; ++i)
{
char A[5];
snprintf(A, 5, "%d", i);
if (slijedeci(A, B) == c)
printf("%d ", i);
}
}
int main()
{
char A[5], B[5];
scanf("%s%s", A, B);
prethodni(A, B);
}
@GeneralSperminator
Copy link

ne da*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment