Surd number
A number is said to be Surd if its square root, cube root, etc are not integers. For example, 9 is not a Surd as square root of 9 is 3, but 5 is Surd as square root of 5 is not integer. Similarly 8 is not a Surd (Cube root of 8 is integer), but 7 is.
Given a range, find if it is Surds or not
Examples:
Input : 4 Output : No 4 is not a Surd number as its square root is an integer. Input : 5 Output : Yes 5 is a Surd number as its square root is not an integer. Input : 8 Output : No 8 is not a Surd number as cube root of 8 is an integer.
The idea is to try every power of all numbers from 2 to √n and check if any power is equal n or not.
C++
// CPP program to find if a number is // Surds or not #include <bits/stdc++.h> using namespace std; // Returns true if x is Surd number bool isSurd(int n) { for (int i=2; i*i<=n; i++) { // Try all powers of i int j = i; while (j < n) j = j * i; if (j == n) return false; } return true; } // driver code int main() { int n = 15; if (isSurd(n)) cout << "Yes"; else cout << "No"; return 0; } |
Java
// Java program to find if a // number is Surds or not class GFG { // Returns true if x // is Surd number static boolean isSurd(int n) { for (int i = 2; i * i <= n; i++) { // Try all powers of i int j = i; while (j < n) j = j * i; if (j == n) return false; } return true; } // Driver Code public static void main(String args[]) { int n = 15; if (isSurd(n)) System.out.println("Yes"); else System.out.println("No"); } } // This code is contributed // by Ankita_Saini |
Python3
# Python3 program to find # if a number is Surd or not. # define a isSurd function which # Returns true if x is Surd number. def isSurd(n) : i = 2 for i in range(2, (i * i) + 1) : # Try all powers of i j = i while (j < n) : j = j * i if (j == n) : return False return True # Driver code if __name__ == "__main__" : n = 15 if (isSurd(n)) : print("Yes") else : print("No") # This code is contributed # by Ankit Rai1 |
C#
// C# program to find if a // number is Surds or not using System; class GFG { // Returns true if x // is Surd number static bool isSurd(int n) { for (int i = 2; i * i <= n; i++) { // Try all powers of i int j = i; while (j < n) j = j * i; if (j == n) return false; } return true; } // Driver Code public static void Main() { int n = 15; if (isSurd(n)) Console.Write("Yes"); else Console.Write("No"); } } // This code is contributed // by ChitraNayal |
PHP
<?php // PHP program to find if // a number is Surds or not // Returns true if // x is Surd number function isSurd($n) { for ($i = 2; $i * $i <= $n; $i++) { // Try all powers of i $j = $i; while ($j < $n) $j = $j * $i; if ($j == $n) return false; } return true; } // Driver code $n = 15; if (isSurd($n)) echo ("Yes"); else echo ("No"); // This code is contributed // by Shivi_Aggarwal ?> |
Yes
Recommended Posts:
- Count number of trailing zeros in Binary representation of a number using Bitset
- Count number of triplets with product equal to given number with duplicates allowed
- Find minimum number to be divided to make a number a perfect square
- Number of times the largest perfect square number can be subtracted from N
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Given number of matches played, find number of teams in tournament
- Build Lowest Number by Removing n digits from a given number
- Count number of ways to divide a number in 4 parts
- Querying maximum number of divisors that a number in a given range has
- Print a number strictly less than a given number such that all its digits are distinct.
- Program to Convert Octal Number to Binary Number
- Find count of digits in a number that divide the number
- Represent a number as a sum of maximum possible number of Prime Numbers
- Find the largest good number in the divisors of given number N
- Find the smallest number whose digits multiply to a given number n
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



