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

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;
}

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

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

Factory Pattern

Factory Method  is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alte...