给定整数区间[A,B]问当中有多少个全然平方数。
输入格式:
多组数据,包括两个正整数A,B 1<=A<=B<=2000000000。
输出格式:
每组数据输出一行包括一个整数。表示闭区间[A,B]中包括的全然平方数的个数。
答题说明输入例子
1 1
1 2
3 10
3 3
输出例子:
1
1
2
0
解答:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{double begin, end;while(cin >> begin){cin >> end;double d_begin = sqrt(begin);int i_begin = sqrt(begin);if(abs(d_begin - i_begin) < 0.000000000001)cout << (int)sqrt(end) - (int)sqrt(begin) + 1 << endl;else cout << (int)sqrt(end) - (int)sqrt(begin) << endl;}return 0;
}
转载于:.html
本文发布于:2024-01-28 07:41:03,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063988695856.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |