Count number of 1 s in the array after N moves | C ++ implementation of the above approach ; Function to count number of perfect squares ; Counting number of perfect squares between a and b ; Function to count number of 1 s in array after N moves ; Driver Code ; Initialize array size ; Initialize all elements to 0
#include <bits/stdc++.h> NEW_LINE using namespace std ; int perfectSquares ( int a , int b ) { return ( floor ( sqrt ( b ) ) - ceil ( sqrt ( a ) ) + 1 ) ; } int countOnes ( int arr [ ] , int n ) { return perfectSquares ( 1 , n ) ; } int main ( ) { int N = 10 ; int arr [ 10 ] = { 0 } ; cout << countOnes ( arr , N ) ; return 0 ; }