Cod sursa(job #138824)

Utilizator toni2007Pripoae Teodor Anton toni2007 Data 19 februarie 2008 11:47:18
Problema Multiplu Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include<stdio.h>
#include<limits.h>
#define CIF 100
int main(){
    int i,y,a,b,cif,minte,min,v[CIF],j;
    freopen("multiplu.in","r",stdin);
    freopen("multiplu.out","w",stdout);
    scanf("%d%d",&a,&b);
    for (i=1;i<=INT_MAX;++i){
        y=i;cif=0;minte=0;min=0;
        while(y){
            ++cif;
            v[cif]=y%2;
            y/=2;
        }
        for (j=cif;j>=1;--j){
            if (v[j]+minte*10<a)
                minte=minte*10+v[j];
            else
                minte=(minte*10+v[j])%a;
        }
        for (j=cif;j>=1;--j){
            if (v[j]+min*10<b)
                min=min*10+v[j];
            else
                min=(min*10+v[j])%b;
        }
        if (minte==0 && min==0){
            for(j=cif;j>=1;--j)
                printf("%d",v[j]);
            printf("\n");
            return 0;
        }
    }
    printf("Imposibil\n");
    return 0;
}