Do I <N + 1 and I <= N are different?

I knew that there was no difference between i <= Nand i < N+1
However, when entering 6 6the program.

if i <= N, then printed

1 6 6
6 1 1
2 3 3
3 2 2

otherwise

1 6 6
6 1 1
2 3 3
3 2 2
3 2 2 2 3 3


I cannot understand why this matters.

#include <iostream>
#include <cmath>

using namespace std;

typedef long long LNT;

LNT gcd(LNT a, LNT b)
{
    if( b == 0)
        return a;

    return gcd(b, a%b);
}

int main()
{
    LNT red, green;
    LNT GCD;
    cin >> red >> green;

    GCD = gcd(red, green);

    //for(LNT i = 1; i<sqrtl(GCD)+1; i++)
    for(LNT i = 1; i<=sqrtl(GCD); i++)   // <- This Line cause the difference 
    {
        if( GCD % i == 0)
        {
            cout << i << " " << red/i << " " << green/i <<endl;
            if( i != GCD/i )
            {
                LNT k = GCD/i;
                cout << k << " " << red/k << " " << green/k <<endl;
            }
        }
    }
}
+4
source share
3 answers

. sqrtl long double, , , - , +1, :

! 2 <= 1.5
2 < 1.5+1
+15

sqrtl return long double :

i <= N i < N+1

.

+2

, i<=n i < n+1, n, , , - sqrt, long double .

0

Source: https://habr.com/ru/post/1625076/


All Articles