Skip to content
Programming101
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • 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
Programming101
Programmingoneonone

Learn everything about programming

HackerEarth Hexadecimal numbers problem solution

YASH PAL, 31 July 2024
In this HackerEarth Hexadecimal numbers problem solution, You are given a range [L, R]. You are required to find the number of integers X in the range such that GCD(X, F(X)) > 1 where F(X) is equal to the sum of digits of X in its hexadecimal (or base 16) representation.
For example, F(27) = 1 + B = 1 + 11 = 12 (27 in hexadecimal is written as 1B). You are aksed T such questions.
HackerEarth Hexadecimal numbers problem solution

HackerEarth Hexadecimal numbers problem solution.

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
#define sz(x) (ll)x.size()
using namespace std;

const ll N =(1e5+5);
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238


long long binpow(long long a, long long b) {
a%=MOD;
long long res = 1;
while (b > 0) {
if (b & 1)
res = (res * a);
a = (a * a);


b >>= 1;
}
res%=MOD;
return res;
}
ll sum(ll x){
ll r = 0;
while(x ){
r += (x%16);
x /= 16;
}
return r;
}
void solve(){
ll l,r;
cin>>l>>r;
ll ans =0;
for(int i=l;i<=r;i++){
ll g = sum(i);
if(__gcd(i,g) > 1){
ans++;
}
}

cout<<ans<<endl;
}


signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);



ll t=1;
cin>>t;
while(t--){
solve();
}

}
coding problems solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

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