编程马拉松分遗产哪里有问题?
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int Gcd(int a,int b)
{
int temp;
while(b!=0)
{/*利用辗除法,直到b为0为止*/
temp=a%b;
a=b;
b=temp;
}
return a;
}
int main()
{
int n,m;
int a[11];
int ans[11];
while (scanf("%d%d",&n,&m)!=EOF)
{
if (n==0&&m==0) break;
int lcm;
for (int i=1;i<=m;i++)
scanf("%d",&a[i]);
lcm=a[1];
for (int i=2;i<=m;i++)
{
int gcd=Gcd(lcm,a[i]);
lcm=lcm/gcd*a[i];
}
int num=0;
int index=0;
while (lcm<n)
lcm=lcm*2;
for (int i=1;i<=m;i++)
{
num=num+lcm/a[i];
ans[++index]=lcm/a[i];
}
if (num==n)
{
for (int i=1;i<=index;i++)
{
if (i<index)
cout<<ans[i]<<' ';
else
cout<<ans[i]<<endl;
}
}
else
printf("Can't Solve\n");
}
}