close

原文

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456

感謝黃建庭大大的翻譯

https://sites.google.com/site/zsgititit/home/c-cheng-shi-she-ji/d186-acm-11461---square-numbers

 

C++

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int a,b,sq;
	while(cin>>a>>b)
	{
		if(a==0&&b==0)//輸入結束 
		{
			break;
		}
		int count=0;
		
		for(int i =a;i<=b;i++)
		{
			sq=sqrt(i);//因為是整數型態所以開根號後也是整數 
					   //所以再乘回來不一定會是原本的數 
			if(sq*sq==i)//將兩數相乘與原本的數進行比較 
			{
				count++;
			}
			
		}
		
		cout<<count<<endl;//輸出 
	}
	return 0;
}
 
arrow
arrow
    文章標籤
    UVa一星題
    全站熱搜
    創作者介紹
    創作者 豪CO 的頭像
    豪CO

    程式道路,必為豐富

    豪CO 發表在 痞客邦 留言(0) 人氣()