-1

I have 2 codes.One of them shows no stdout response(with large inputs) while the other works just fine.

code 1

#define lli long long int

using namespace std;

int main()
{

        lli n,a,b,k,app,chf;

        app=0,chf=0;
        cin>>n>>a>>b>>k;
        for(lli j=1;j<=n;j++)
        {
            if(j%a==0){if(j%b!=0)app++;}
        }
        for(lli int j=1;j<=n;j++)
        {
            if(j%b==0){if(j%a!=0)chf++;}
        }

        cout<<app+chf;

}

code 2

    long long int n, a, b, k;
    std::cin >> n >> a >> b >> k;
    long long int na = n / a;
    long long int nb = n / b;
    long long int nab = n / (a * b);
    /*
    if (na + nb - 2 * nab >= k)
        std::cout << "Win\n";
    else
        std::cout << "Lose\n";*/
        std::cout<<(na+nb-2*nab);

The result on the 1st code doesn't arrive even if I wait for sufficently long time.Even if the code is really slow ,why doesn't the output arrive(even though late).

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 3
    Print a newline `'\n'` or `std::endl` at the end of the line. – Retired Ninja Feb 07 '19 at 06:01
  • 1
    You may also need to know this: https://stackoverflow.com/questions/22026751/c-force-stdcout-flush-print-to-screen – Soumya Kanti Feb 07 '19 at 06:33
  • 2
    Unrelated: The names and even the type in `lli n,a,b,k,app,chf;` contain little to no information. This makes the code hard to read, hard to maintain, and hard to debug. That can make you hard to employ. – user4581301 Feb 07 '19 at 06:38

1 Answers1

0

You are asking 4 numbers from the standard input. After each number you need to press enter. E.g.:

1 <enter>
2 <enter>
3 <enter>
4 <enter>
0 <- this is the result
jav
  • 583
  • 5
  • 15