Solutions of Square numbers counting - MarisaOJ: Marisa Online Judge

Solutions of Square numbers counting

Select solution language

Write solution here.


User Avatar HuyNguyenCong    Created at    0 likes

# $\textbf{Square Numbers Counting}$ --- ## $\textbf{How to solve this problem?}$ $\text{There are two solutions for this problem: }$ - $\textbf{A Simple solution}$ $\text{is to traverse through all memebers from 1 to n and or every number check if it is perfect square or not.}$ - $\textbf{An efficient solution}$ $\text{is to use the formula: }$ `floor(sqrt(n))` --- ## $\textbf{Full Code}$ ### C++ ```cpp #include <iostream> #include <cmath> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long a; // because 1 <= a <= 1e18 cin >> a; cout << (int)floor(sqrt(a)); return 0; } ``` ### Python ```python import math a = int(input()) print(math.floor(math.sqrt(a))) ``` --- $\LARGE \textit{Happy Coding!}$