Pagini recente » Cod sursa (job #3232645) | Cod sursa (job #1987710) | Cod sursa (job #1267850) | Cod sursa (job #2262240) | Cod sursa (job #2146037)
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
bool v[25] , cp[25];
long long number_construct(int n)
{
long long nr = 0 , i;
for(i = 1 ; i <= n ; i ++)
nr = nr * 10 + v[i];
return nr;
}
int main()
{
freopen("multiplu.in" , "r" , stdin);
freopen("multiplu.out" , "w" , stdout);
int a , b , i , gasit , n;
long long nr;
scanf("%d%d" , &a , &b);
gasit = 0;
n = 1;
v[1] = 1;
if(a == 1 && b == 1)
printf("1\n");
else
{
while(gasit == 0)
{
n ++;
v[1] = 1;
for(i = 2 ; i <= n ; i ++)
v[i] = 0;
memcpy(cp , v , sizeof(v));
nr = number_construct(n);
if(nr % a == 0 && nr % b == 0)
{
gasit = 1;
break;
}
for(i = 1 ; i < n && gasit == 0 ; i ++)
{
memcpy(v , cp , sizeof(cp));
v[n - i + 1] = 1;
memcpy(cp , v , sizeof(v));
do
{
nr = number_construct(n);
if(nr % a == 0 && nr % b == 0)
gasit = 1;
}
while(next_permutation(v + 2 , v + n + 1) && gasit == 0);
}
}
printf("%lld\n" , nr);
}
return 0;
}