বৃহস্পতিবার, ২২ জুন, ২০১৭

Count square numbers in a range(n,m)

Input  : n = 5, m = 100
Output : 8
The numbers with odd factors are 9, 16, 25, 
36, 49, 64, 81 and 100

Input  : n = 8, m = 65
Output : 6

Input  : n = 10, m = 23500
Output : 150
source code:-

#include <bits/stdc++.h>
using namespace std;
 
int Squares(int n, int m)
{
   return (int)pow(m,0.5) - (int)pow(n-1,0.5);
}
 
// Driver code
int main()
{
    int n = 5, m = 100;
    cout << "Count is " << Squares(n, m);
    return 0;
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন

Factorization with prime Sieve

vector <int> prime; char sieve[1000009]; int N=1000009; void primeSieve ( ) { sieve[0] = sieve[1] = 1; prime.push_back(2); ...