网易2017年内推笔试题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gao158190523/article/details/65694900
小易有一个圆心在坐标原点的圆,小易知道圆的半径的平方。小易认为在圆上的点而且横纵坐标都是整数的点是优雅的,小易现在想寻找一个算法计算出优雅的点的个数,请你来帮帮他。
例如:半径的平方如果为25
优雅的点就有:(+/-3, +/-4), (+/-4, +/-3), (0, +/-5) (+/-5, 0),一共12个点。 
输入描述:
输入为一个整数,即为圆半径的平方,范围在32位int范围内。


输出描述:
输出为一个整数,即为优雅的点的个数

输入例子:
25

输出例子:

12

#include<iostream>
#include<math.h>
using namespace std;

int getGraceNum(int length_squ)
{
	int count = 0;
	int j=(int)(sqrt(length_squ)*1.0);
	for(int i=1;i<=j;i++)
	{
		double other = sqrt(length_squ-pow(i,2));
		other = other - (int)other;
		if(other == 0){
				count += 4;
		}
	}
	return count;

}

int main()
{
	int length_squ;
	cin>>length_squ;
	cout<<getGraceNum(length_squ);
	return 0;
}


猜你喜欢

转载自blog.csdn.net/gao158190523/article/details/65694900
今日推荐