A number is called a smart number if it has an odd number of factors. Given some numbers, find whether they are smart numbers or not.
Example:
Input: n = 4
Output: YES
Approach
C++
#include <bits/stdc++.h>using namespace std;bool is_smart_number(int num){int val = (int)sqrt(num);if ((double)num / val == val)return true;return false;}int main(){int num = 4;bool ans = is_smart_number(num);if (ans){cout << "YES" << endl;}elsecout << "NO" << endl;return 0;}
No comments:
Post a Comment