# 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.
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

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 ` `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

 ` `

Output:

```Yes
```

My Personal Notes arrow_drop_up Do your best to show the world what you are capable of

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.