মঙ্গলবার, ২৫ অক্টোবর, ২০১৬

Find total number of Rectangles (including squares) in a N*N cheesboard

#include<bits/stdc++.h>
using namespace std;

main()
{
    long long n;
    cin>>n;
    while(n--)
    {
        long long a;
        cin>>a;
        a=(((a*(a+1))/2)*((a*(a+1))/2));
        cout<<a<<endl;
    }
}

Find total number of Rectangles (excluding squares) in a N*N cheesboard

#include<bits/stdc++.h>
using namespace std;

main()
{
    long long n;
    cin>>n;
    while(n--)
    {
        long long a;
        cin>>a;
        a=(((a*(a+1))/2)*((a*(a+1))/2))-((a*a+a)*(2*a+1))/6;
        cout<<a<<endl;
    }
}

find the maximum number of squares in (n*n) grid cheesboard

If there is n*n grid cheesboard
Now find the maximum number of squares possible????

Formula:-

((n*n + n)*(2*n+1))/6 or ((n*(n+1))*(2*n+1))/6

if(n==1) ans=1;
n==2 ans=5;
n==3 ans=14;
n==4 ans=30;

Factory Pattern

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