Bug(?) in Dev C++

Revision en4, by 014-12352-09-Nursultan, 2018-02-19 09:24:29

Hello Codeforces!

I found a bug(?) while I was solving 939B - Хомячковая ферма, 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

Tags bug, devc++

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English 014-12352-09-Nursultan 2018-02-19 09:24:29 44 Tiny change: '~~\n\nHow?' -> '~~\n\nHow?\n\n**UPD:** It works only in 32bit compiler'
en3 English 014-12352-09-Nursultan 2018-02-19 06:41:26 2 Tiny change: 'n[cut]\n\n1)\n\n' -> 'n[cut]\n\n\n1)\n\n'
en2 English 014-12352-09-Nursultan 2018-02-19 06:40:39 9 Tiny change: ' code:\n\n1)\n\n' -> ' code:\n\n[cut]\n\n1)\n\n'
en1 English 014-12352-09-Nursultan 2018-02-19 06:37:12 2137 Initial revision (published)