#include #include using namespace std; int main() { int M,D; cin >> D; vector all; int best; double best2; int test; double test2; while(D!=0) { cin >> M; best=0; best2=0; test=0; test2=0; all.clear(); for (int i=0;i> tmp; all.push_back(tmp); } /*for (int i=0;i< all.size();i++) cout << all[i] << " "; cout << endl;*/ for (int i=all.size()-1;i>=1;--i) //for (int j=i-1;j>=0;--j) for (int j=0;jall[j]) { test2=all[i]/all[j]; if (test2>best2) { best2=test2; best=((int(M/all[j]))*all[i])-((all[j]*int(M/all[j]))); } } } cout << best << endl; cin >> D; } return 0; }