Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerEarth Bricks and Building problem solution

YASH PAL, 31 July 2024
In this HackerEarth Palindromic Bricks and Building problem solution, An old planet called Alpha has been found but it is destructed completely. Archaeologists after the expedition found a map that depicts all the buildings that were in Alpha. In the map following facts were stated:
  1. Buildings were made of identical bricks and all the bricks were equal-sized.
  2. All the buildings and bricks were 2D rectangles of some height and an equal width.
  3. A building is formed by putting bricks one on the another. The height of the building is the sum of the heights of bricks. None of the bricks used are ever broken or rotated.
Now you have q queries.
Each query contains an integer k. For every query, you have to print the count of buildings that can be made if you had an infinite number of bricks of size k adhering to the above rules.
HackerEarth Bricks and Building problem solution

HackerEarth Bricks and Building problem solution.

#include<bits/stdc++.h>
#define LL long long int
#define M 1000000007
#define MM 1000000009
#define reset(a) memset(a,0,sizeof(a))
#define rep(i,j,k) for(i=j;i<=k;++i)
#define per(i,j,k) for(i=j;i>=k;--i)
#define print(a,start,end) for(i=start;i<=end;++i) cout<<a[i];
#define endl "n"
#define inf 100000000000000
LL pow(LL a,LL b,LL m){LL x=1,y=a;while(b > 0){if(b%2 == 1){x=(x*y);if(x>m) x%=m;}y = (y*y);if(y>m) y%=m;b /= 2;}return x%m;}
LL gcd(LL a,LL b){if(b==0) return a; else return gcd(b,a%b);}
LL gen(LL start,LL end){LL diff = end-start;LL temp = rand()%start;return temp+diff;}
using namespace std;
int a[100011];
int ct[1000001];
void update(int val)
{
int lim = sqrt(val);
for(int i = 1; i <= lim ; i++)
{
if(val % i == 0)
{
ct[i]++;
if(val != i*i)
{
ct[val/i]++;
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for(int i = 1; i <= n ; i++)
{
cin >> a[i];
update(a[i]);
}

int q;
cin >> q;
for(int i = 1; i <= q; i++)
{
int k;
cin >> k;
cout << ct[k] << endl;
}
}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes