# UVA 11461 Square Numbers ## 題目連結 [UVA 11461](https://vjudge.net/problem/UVA-11461) ### 題目內容 A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers a and b you will have to find out how many square numbers are there between a and b (inclusive). ### 輸入限制 The input file contains at most 201 lines of inputs. Each line contains two integers a and b (0 < a ≤ b ≤ 100000). Input is terminated by a line containing two zeroes. This line should not be processed. ### 輸出限制 For each line of input produce one line of output. This line contains an integer which denotes how many square numbers are there between a and b (inclusive). ### 解題思路 1.確認開根號相乘是否為當下的數,需要注意取跟號前面要加int,因為取根號後可能是小數,相乘也有可能等於當下的數 ### 程式碼 ```cpp= #include<bits/stdc++.h> using namespace std; int main(){ long long n,m,cot; while(cin>>n>>m){ cot=0; if(n==0 && m==0){ break; } for(int i=n;i<=m;i++){ if((int)sqrt(i)*(int)sqrt(i)==i){ cot++; } } cout<<cot<<endl; } } ``` ## 測資 ### Sample input 1 4 1 10 0 0 ### Sample output 2 3 ## 中文題目連結 [zerojudge d186](https://zerojudge.tw/ShowProblem?problemid=d186)