926A - 2-3-numbers - CodeForces Solution


implementation math *1300

Please click on ads to support us..

Python Code:

l, r = map(int, input().split())
result = set()
for x in range(31):
    for y in range(20):
        v = 2**x*3**y
        if l <= v <= r:
            result.add(v)
print(len(result))

C++ Code:

#include <bits/stdc++.h>

using namespace std;

// /*
//                                                //////////**DEFINES - START**//////////

#define ret return
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define be(x) x.begin()
#define en(x) x.end()
#define sz(x) x.size()
#define for0(i,n) for (long long  i = 0; i < (n); ++i)
#define for1(i,n) for (long long i = 1; i < (n); ++i)
#define rfor(i,n) for (long long i = (n) - 1; i >= 0; --i)
#define rfor1(i,n) for (long long i = (n) - 1; i >= 1; --i)
#define rep(i,a,n) for (long long i = a; i < ll(n); ++i)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fastIO() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define con continue
#define pb push_back
#define pob pop_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ins insert
#define len(s) (s).length()
#define gi greater<int>()
#define gll greater<long long>()
#define gstr greater<string>()
#define gpll greater<pair<long long, long long>>()
#define rast(x1,y1,x2,y2) sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define rev reverse
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define rs resize
#define last(a) a.back()
#define co count
#define ba(a) a.back()
#define um unordered_map
//#define sqrt sqrt1
#ifdef _DEBUG
bool local = true;
#else
bool local = false;
#endif

//                                                \\\\\\\\\\**DEFINES - END**\\\\\\\\\\
// */

// /*
//                                                //////////**CONSTANTS - START**//////////

const long double pi = 3.141592653589793238462643383279;
const long long mod1 = 1e9 + 7;
const long long mod2 = 998244353;
const long long MAXLL = 9223372036854775807;
const long long MAXINT = 2147483647;

//                                                \\\\\\\\\\**CONSTANTS - END**\\\\\\\\\\
// */

// /*
//                                                //////////**TYPEDEFS - START**//////////

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef pair<double, double> pdd;
typedef long double ld;
typedef double D;
typedef vector<ld> vld;
typedef vector<pair<ld, ld>> vpld;
typedef string str;
typedef set<ll> sll;
typedef set<int> si;
typedef set<str> ss;
typedef set<pii> spii;
typedef multiset<int> msi;
typedef multiset<ll> msll;
typedef multiset<str> mss;
typedef multiset<pii> mspii;
typedef multiset<pll> mspll;
typedef map<str, str> mps;
typedef map<int, int> mpi;
typedef map<ll, ll> mpll;
typedef map<int, vi> mpvi;
typedef map<int, vll> mpvll;
typedef map<char, int> mpci;
typedef multimap<ll, ll> mmpll;
typedef multimap<str, str> mmps;
typedef multimap<int, int> mmpi;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long double>> vvld;
typedef vector<vector<char>> vvc;
typedef vector<vs> vvs;
typedef vector<D> vD;
typedef set<pair<ll, ll>> spll;
typedef vector<bool> vb;
typedef set<char> sc;
typedef queue<int> qi;
typedef queue<ll> qll;
typedef queue<bool> qb;
typedef queue<pair<ll, ll>> qpll;
typedef vector < vector<pair<int, int>>> vvpii;
typedef vector < vector<pair<ll, ll>>> vvpll;

//                                                \\\\\\\\\\**TYPEDEFS - END**\\\\\\\\\\
// */

// /*
//                                                //////////**TEMPLATES - START**//////////


template <typename T>
istream& operator >> (istream& in, vector <T>& a)
{
	for (T& i : a) in >> i;
	return in;
}
template <typename T1, typename T2>
istream& operator >> (istream& in, vector <pair<T1, T2>>& a)
{
	for (pair<T1, T2>& i : a) in >> i.fi >> i.se;
	return in;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a)
{
	for (auto i : a)
	{
		out << i << " ";
	}
	return out;
}
template <typename T1, typename T2>
ostream& operator << (ostream& out, vector <pair<T1, T2>>& a)
{
	for (pair<T1, T2> i : a) out << i.fi << " " << i.se << endl;
	return out;
}
template <typename T1>
ostream& operator << (ostream& out, vector <vector<T1>>& a)
{
	for (vector<T1> i : a)
	{
		for (T1 j : i) out << j << " ";
		out << endl;
	}
	return out;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b)
{
	b = (T1)b;
	ret a > b ? b : a;
}
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b)
{
	b = (T1)b;
	ret a > b ? a : b;
}
template <typename T1, typename T2>
inline void amin(T1& a, T2 b)
{
	a = min(a, b);
}
template <typename T1, typename T2>
inline void amax(T1& a, T2 b)
{
	a = max(a, b);
}


//                                                \\\\\\\\\\**TEMPLATES - END**\\\\\\\\\\
// */




// This bear is a good alternative to duck!!!
/*
	▒▒▒▒      ▒▒▒▒▒▒
  ▒▒░░░░▒▒▒▒▒▒▒░░░░▒▒
 ▒▒░░░░░░▒▒▒▒▒░░░  ░▒▒
▒▒░   ░░▒▒▒▒▒▒▒░░  ░▒▒
▒▒░  ░▒▒▒▒▒▒▒▒▒▒▒ ░▒
 ▒░░▒▒▒▒▒▒█▒▒▒▒▒█▒▒
   ▒▒▒▒▒▒░██▒▒▒▒██ ▒
   ▒▒▒▒▒░░░░███░░░▒▒
   ▒▒▒▒▒░░   ███    ▒▒
	▒▒░░  ▀▄▄▄▄▄▄▀░▒
	 ▒▒▒░     ▀▀ ░▒▒
   ▒▒▒░▒░░░▒▒▒░ ▒▒▒▒▒
  ▒▒▒░▒▒▒▒▒░░░▒░▒▒▒▒▒▒
 ▒▒▒░▒▒▒▒   ▒▒  ▒▒▒▒▒▒▒
 ▒▒▒░▒░░         ░▒▒▒▒
 */

long long rnd(long long l, long long r)
{
	long long a = rand() % (r - l + 1) + l; ret a;
}
double getTime()
{
	ret clock() / (double)CLOCKS_PER_SEC;
};
void solve();
int main()
{
	setlocale(LC_ALL, "rus");
	srand(time(0));
	fastIO();
	if (local)
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	ll t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	if (local)
	{
		cout.precision(32);
		cout << endl << fixed << "time = " << getTime();
	}
}



/*
	___        __              __   ______          __        _____ __             __          __  __
   /   | _____/ /___  ______ _/ /  / ____/___  ____/ /__     / ___// /_____ ______/ /______   / / / /__  ________
  / /| |/ ___/ __/ / / / __ `/ /  / /   / __ \/ __  / _ \    \__ \/ __/ __ `/ ___/ __/ ___/  / /_/ / _ \/ ___/ _ \
 / ___ / /__/ /_/ /_/ / /_/ / /  / /___/ /_/ / /_/ /  __/   ___/ / /_/ /_/ / /  / /_(__  )  / __  /  __/ /  /  __/
/_/  |_\___/\__/\__,_/\__,_/_/   \____/\____/\__,_/\___/   /____/\__/\__,_/_/   \__/____/  /_/ /_/\___/_/   \___/
*/



void solve()
{
	ll l, r;
	cin >> l >> r;
	ll a = 1;
	ll ans = 0;
	while (a <= r)
	{
		ll b = 1;
		while (a * b <= r)
		{
			if (a * b >= l)
			{
				ans++;
			}
			b *= 3;
		}
		a *= 2;
	}
	cout << ans;
}


Comments

Submit
0 Comments
More Questions

1732. Find the Highest Altitude
709. To Lower Case
1688. Count of Matches in Tournament
1684. Count the Number of Consistent Strings
1588. Sum of All Odd Length Subarrays
1662. Check If Two String Arrays are Equivalent
1832. Check if the Sentence Is Pangram
1678. Goal Parser Interpretation
1389. Create Target Array in the Given Order
1313. Decompress Run-Length Encoded List
1281. Subtract the Product and Sum of Digits of an Integer
1342. Number of Steps to Reduce a Number to Zero
1528. Shuffle String
1365. How Many Numbers Are Smaller Than the Current Number
771. Jewels and Stones
1512. Number of Good Pairs
672. Richest Customer Wealth
1470. Shuffle the Array
1431. Kids With the Greatest Number of Candies
1480. Running Sum of 1d Array
682. Baseball Game
496. Next Greater Element I
232. Implement Queue using Stacks
844. Backspace String Compare
20. Valid Parentheses
746. Min Cost Climbing Stairs
392. Is Subsequence
70. Climbing Stairs
53. Maximum Subarray
1527A. And Then There Were K