Hello Codeforces!
I found a bug(?) while I was solving 939B - Hamster Farm, and my code: 1)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll INF = 1e18 + 1;
main()
{
ll n, m, r = 0;
cin >> n >> m;
ll x[m + 1];
double mn = -INF;
for(int i = 1; i <= m; i ++)
{
cin >> x[i];
if(n % x[i] == 0)
r = 1;
}
double d;
for(int i = 1; i <= m; i ++)
{
if(r == 0)
mn = max(mn, double(n) / double(x[i]));
else if(r == 1 && n % x[i] == 0)
mn = max(mn, n / double(x[i]));
}
if(n == 0)
{
cout << 1 << " " << 0;
return 0;
}
double u = double(double(n) / mn);
cout << u << "\n";
for(int i = 1; i <= m; i ++)
{
if(u == double(x[i]))
{
cout << i << " ";
break;
}
}
ll t = mn;
cout << t;
}
/*
120 7
109 92 38 38 49 38 92
*/
And another one is bit changed.
2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll INF = 1e18 + 1;
main()
{
ll n, m, r = 0;
cin >> n >> m;
ll x[m + 1];
double mn = -INF;
for(int i = 1; i <= m; i ++)
{
cin >> x[i];
if(n % x[i] == 0)
r = 1;
}
double d;
for(int i = 1; i <= m; i ++)
{
if(r == 0)
mn = max(mn, double(n) / double(x[i]));
else if(r == 1 && n % x[i] == 0)
mn = max(mn, n / double(x[i]));
}
if(n == 0)
{
cout << 1 << " " << 0;
return 0;
}
double u = double(double(n) / mn);
//cout << u << "\n";
for(int i = 1; i <= m; i ++)
{
if(u == double(x[i]))
{
cout << i << " ";
break;
}
}
ll t = mn;
cout << t;
}
/*
120 7
109 92 38 38 49 38 92
*/
1) Input
28 3
5 6 30
Output
5
1 5
2) Input
28 3
5 6 30
Output
5
How?
UPD: It works only in 32bit compiler
Well, the second program outputs "1 5" in my environment (64bit windows, tdm-g++ 4.9.2 64bit compiler, dev-c++) ,which is correct.