Pagini recente » Cod sursa (job #1274297) | Cod sursa (job #797822) | Cod sursa (job #2567018) | Rating Agricimihai (am.001) | Cod sursa (job #2229103)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("multiplu.in");
ofstream fout("multiplu.out");
int gcd(int a,int b) {
if(b==0) {
return a;
}
return gcd(b,a%b);
}
const int N=2000000;
int q[N],st,dr;
int t[N],cif[N];
bool viz[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int a,b;
fin>>a>>b;
int n=a*b/gcd(a,b);
if(n==1) {
fout<<"1\n";
return 0;
}
fout<<n<<"\n";
st=dr=q[1]=cif[1]=viz[1]=1;
while(st<=dr) {
int cur=q[st];
st++;
int x=(cur*10+0)%n;
int y=(cur*10+1)%n;
if(viz[x]==0) {
viz[x]=1;
t[x]=cur;
cif[x]=0;
q[++dr]=x;
}
if(viz[y]==0) {
viz[y]=1;
t[y]=cur;
cif[y]=1;
q[++dr]=y;
}
}
vector<int>ans;
int poz=0;
while(t[poz]) {
ans.push_back(cif[poz]);
poz=t[poz];
}
reverse(ans.begin(),ans.end());
fout<<1;
for(auto itr:ans) {
fout<<itr;
}
fout<<"\n";
return 0;
}
/**
**/