我曾经知道i <= N
和i < N+1
之间没有区别
但是,当我输入6 6
进行编程时。
如果i <= N
则打印
1 6 6
6 1 1
2 3 3
3 2 2
否则
1 6 6
6 1 1
2 3 3
3 2 2
3 2 2 2 3 3
我无法弄清楚它为何会产生影响
#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;
}
}
}
}
答案 0 :(得分:15)
仅适用于整数值。当sqrtl
返回long double
时,如果它是小数,那么对于小数,如果您将原始分数与分数+1
进行比较,其中另一个整数适合:
! 2 <= 1.5
2 < 1.5+1
答案 1 :(得分:2)
sqrtl
返回long double
您的假设:
之间没有区别
i <= N
和i < N+1
错了。
答案 2 :(得分:0)
好吧,- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult) result
{
switch (result) {
case MessageComposeResultCancelled:
break;
case MessageComposeResultFailed:
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to send SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[warningAlert show];
break;
}
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
和i<=n
之间没有区别,因为它们都只运行到i < n+1
,但你所做的是n
,返回long double并且对于它们不一定是一样的。