description
stringlengths
35
9.39k
solution
stringlengths
7
465k
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; bool lucky(long long int a) { while (a) { if (a % 10 != 4 && a % 10 != 7) return false; a /= 10; } return true; } vector<long long int> gen() { vector<long long int> res; for (int k = 1; k < 11; k++) { for (int i = 0; i < (1 << k); i++) { long lo...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
// practice with rainboy import java.io.*; import java.util.*; public class CF121C extends PrintWriter { CF121C() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF121C o = new CF121C(); o.main(); o.flush(); } long lucky(int b) { return b == 1 ? 0 : luc...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.*; import java.util.*; import java.lang.reflect.Array; import java.math.*; public class lucksum { public static long go(long m) { long res=0; Queue<Long> l=new LinkedList<Long>(); l.add(new Long(0)); do{ Long t=l.remove(); if(t.compareTo(new Long(m))<=0) { res++; l.add(t*10+4);...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; vector<long long> V; vector<long long> F; vector<long long> out; bool used[30]; long long per[20]; void dfs(int depth, string S) { if (depth > 11) return; if (S.length() != 0) { long long fuck; istringstream st(S); st >> fuck; V.push_back(fuck); } df...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.security.KeyStore.Builder; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class LuckyPermutation { static ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const long long dx[] = {4LL, 7LL}; vector<int> lucky; vector<long long> P; int main() { P.push_back(1); for (long long i = 1; P.back() <= 1000000000; i++) P.push_back(P[i - 1] * i); int n, k; cin >> n >> k; if (n < 13 && P[n] < k) { cout << -1; return (0);...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; import java.util.Arrays; import java.util.Comparator; public class CF121C { public static void main(String[] args) throws Exception { boolean local = System...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int n, k, l, a[2000], mk[15], s[15]; long long f[15]; map<int, bool> lc; void F(long long x) { if (x > 1e9) return; if (x > 0) { a[++l] = x; lc[x] = 1; } F(x * 10LL + 4LL); F(x * 10LL + 7LL); } int main() { f[0] = 1LL; for (int i = 1; i <= 13; i++) f[i...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.util.*; import java.io.*; import static java.lang.Math.*; public class C{ public static void main(String[] args) throws Exception{ new C().run(); } static final long M = 4444444444L; ArrayList<Long> ls = new ArrayList<Long>(); void dfs(long cur){ if(cur > M)return; ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int M = 10 + 10; long long int lucky[10000]; long long int fac(long long int n) { long long int ans = 1; for (long long int i = 1; i <= n; i++) { ans = ans * i; } return ans; } bool islucky(long long int x) { bool ok = true; while (x) { if (x % 10 ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; public class Main { static long[] fact; public static void main(String[] args) { // ArrayList<String> all = new ArrayList<String>(); // char[] a = "1234567".toCharArray(); // // go...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long numlucky(long long i, long long bound) { if (i > bound) return 0; else return 1 + numlucky(i * 10 + 4, bound) + numlucky(i * 10 + 7, bound); } bool check(long long i) { if (i <= 0) return false; while (i > 0) { int a = i % 10; if (a != 4 &&...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.*; import java.math.*; import java.util.*; /*public class TaskC { } */ public class TaskC implements Runnable { // based on Petr's template private void solve() throws IOException { ArrayList< Integer > luckies = new ArrayList< Integer >(); for ( int i = 1; i <= 9; i ++ ) for ( int mask = 0; m...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; vector<long long> luckies; long long x; void gen_luck(int k, int pos, long long cur) { if (k == pos) { x = cur; if (cur <= 1e10) luckies.push_back(cur); } else { gen_luck(k, pos + 1, cur * 10 + 4); gen_luck(k, pos + 1, cur * 10 + 7); } } void Init() { ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int table[20]; long long tot = 0; int nns[20]; bool isluck(int k) { while (k) { if (k % 10 != 4 && k % 10 != 7) return false; k /= 10; } return true; } int luckns[2000]; int tol = 0; void maketable(int i, int np) { if (i == 9) return; int np1 = np * 10 + 4...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long jc[15]; int da[15]; void sjr(int a, long long b, long long c) { sort(da + a, da + a + c); if (c == 1) return; if (b <= jc[c - 1]) sjr(a + 1, b, c - 1); for (long long i = 1; i <= c; i++) { if (b <= i * jc[c - 1]) { swap(da[a], da[a + i - 1]); ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int luck[5000], top; int a[20], fa[20] = {1}; bool used[20]; void make(long long x) { if (x > 1e9) return; luck[top++] = x; make(x * 10 + 4); make(x * 10 + 7); } bool is(int x) { return x == 0 || (x % 10 == 4 || x % 10 == 7) && is(x / 10); } void inttoarray(int k, i...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> long long b[32] = {0}; bool f(int x) { if (x <= 0) { return false; } while (x) { if (x % 10 != 4 && x % 10 != 7) { return false; } x /= 10; } return true; } int get(int x) { int w = 0, s = 0, t = 0, i = 0, xx = 0, ans = 0; long long now = 0; xx = x; while...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.util.ArrayList; import java.util.Scanner; public class e { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(), k = in.nextInt(); if(k > count(n)) { System.out.println(-1); return; } int ans = 0; int mi = Math.max(1, n-13); find(""); for...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.util.*; import java.io.*; public class C121 { public static long[] fact = new long[15]; public static void main(String[] args) throws IOException { List<Long> list = new ArrayList<Long>(); for (int len = 1; len <= 10; len++) { for (int which = 0; which < (1<<len); which++...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long fac[51]; map<long long, bool> lc; int32_t main() { vector<long long> all; for (long long i = 1; i <= 10; ++i) { for (long long j = 0; j <= i; ++j) { vector<long long> v; for (long long k = 0; k < j; ++k) v.push_back(4); for (long long k =...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.awt.*; import java.io.*; import java.math.*; import java.util.*; import static java.lang.Math.*; public class BetaRound91_Div1_C implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok; public static void main(String[] args) { new Thread(null, new BetaRound91...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
digits = [4, 7] nums = [4, 7] LIM = 10**10 while nums[-1] < LIM: nums = list(set(nums + [num*10 + digit for digit in digits for num in nums])) lucky_nums = list(sorted(nums)) def e(n, k): fact = [1, 1] x = 2 while True: new = fact[x-1] * x if new > LIM: break fact....
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.*; import java.util.*; import java.math.*; public class Main implements Runnable { BufferedReader reader; StringTokenizer strtok; HashSet<Long> happyNums = new HashSet<Long>(); int[] digits = new int[20]; void fillList(int count, int position) { digits[posi...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; public class E { static int[] Fac; static int[] P; static int n; static HashSet<Integer> H = new HashSet<Integer>(); static int count = 0; static int start; static ArrayList<Long> Q = new ArrayList<Long>(); ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; vector<long long> v, ext; long long f[20]; bool vis[20]; bool chck(long long j) { while (j) { if (j % 10 != 4 && j % 10 != 7) break; j /= 10; } return j == 0; } int main() { long long i, n, k, st, sum, j, pre, sz, ans; f[0] = 1; for (i = 1; i <= 13; i++)...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long l[5010]; int tot; long long ans, n, k; void prepare() { tot = 2; l[0] = 4, l[1] = 7; for (int i = 0; i < tot; i++) if (l[i] > 2e9) break; else l[tot++] = l[i] * 10 + 4, l[tot++] = l[i] * 10 + 7; } bool inside(long long t) { for (int i =...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; void run(); int main() { ios::sync_with_stdio(0); run(); } long long fac[20] = {1}; bool lucky(long long i) { return i == 0 or ((i % 10 == 4) or (i % 10 == 7)) and lucky(i / 10); } void run() { long long n, m; cin >> n >> m; --m; for (long long i = 1; i < 20; ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long int fact[14]; int n, k; int cs, s; vector<int> v; vector<long long int> lnum; void Set() { fact[0] = 1; for (long long int i = 1; i < 14; i++) fact[i] = i * fact[i - 1]; } void create_lucky(int i) { for (int i = cs; i < s; i++) lnum.push_back(lnum[i] * 1...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.fill; import static java.util.Arrays.binarySearch; import static java.util.Arrays.sort; public class Main { public static void main(String[] args) throws IOException { new Thread(null, new Runnable() { public vo...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const long long Fac[14] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800LL}; int Total, Data[5000]; bool Lucky(int T) { while...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int n, k, len; long long base[20]; int num[20]; bool mark[20]; int solve(int x) { int ret = 0; for (int L = 1; L <= 9; L++) for (int i = 0; i < (1 << L); i++) { int k = 0; for (int j = 0; j < L; j++) k = k * 10 + ((i & (1 << j)) ? 4 : 7); if (k <= ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int getall(long long x, int n) { if (x > n) return 0; return 1 + getall(x * 10 + 4, n) + getall(x * 10 + 7, n); } bool is_good(int x) { if (!x) return 0; while (x) { if (x % 10 != 4 && x % 10 != 7) return 0; x /= 10; } return 1; } vector<int> kth(int n, ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int Lucky[1024], size; void dfs(int r, int val) { if (val) Lucky[size++] = val; if (r == 9) { return; } dfs(r + 1, val * 10 + 4); dfs(r + 1, val * 10 + 7); } bool isLucky(int x) { while (x) { if (x % 10 != 4 && x % 10 != 7) return false; x /= 10; }...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const int N = 100100; int a[N], cnt, n, k; long long F[111], sum; const int IDX[] = {4, 7}; void DP(int id) { if (sum > n) return; if (sum) a[++cnt] = sum; for (int i = 0; i < 2; i++) { sum = sum * 10 + IDX[i]; DP(i + 1); sum /=...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long int mul[1000]; int i, j, n, m, t, tt, k; void prepare() { mul[0] = 1; i = 0; while (mul[i] < 2000000000) { mul[i + 1] = (i + 1) * mul[i]; i++; } tt = i; } void kper(int p[1000], int n, long long int k) { bool checked[1000]; memset(checked, 0,...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const long long nmax = 100; vector<long long> lucky; long long s_3(long long i) { string s = ""; long long x = i; while (x) { s += char(x % 3); x /= 3; } x = 0; long long k = 1; for (int j = 0; j < s.size(); j++) x += k * (long long)s[j], k *= 10; re...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int per[20]; int fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600}; bool used[20]; int KT(int *s, int n) { int sum = 0; for (int i = 0; i < n; ++i) { int cnt = 0; for (int j = i + 1; j...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int N = 20; const int K = 16; long long f[N]; vector<long long> get_per(long long n, long long k) { f[0] = 1; for (int i = 1; N > i; i++) { f[i] = f[i - 1] * i; } vector<long long> ret; ret.resize(n); set<int> st; for (int i = 1; n >= i; i++) { s...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long f[20]; vector<long long> lu; void go(int x, int y, long long p) { if (x == y) return; lu.push_back(p * 10 + 4); lu.push_back(p * 10 + 7); go(x, y + 1, p * 10 + 4); go(x, y + 1, p * 10 + 7); } bool ok(long long x) { if (!x) return 0; while (x) { i...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int permutation[100]; long long fact[100]; void writeFact(int n) { fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; } void kthPermutation(int n, int i) { i--; int j, k = 0; for (k = 0; k < n; ++k) { permutation[k] = i / fact[n - 1 - k]; ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> const int N = 100010; const int inf = 0x3f3f3f3f; using namespace std; long long dp[N]; int used[21]; bool vis[21]; void dfs(int n, long long k, int cnt) { if (n == 0) return; int id = 1; for (int i = 1; i < n; i++) if (k > dp[n - 1]) k -= dp[n - 1], id = i + 1; else b...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int islucky(long long int a) { long long int temp = a; if (temp == 0) return 0; while (temp != 0) { if (temp % 10 != 4 && temp % 10 != 7) return 0; temp /= 10; } return 1; } int main() { long long int v[10010]; memset(v, 0, sizeof(v)); v[0] = 4; v[...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ' '; cerr << endl; } long long int luck[100005]; int cnt = 0; long long int n, k; long long int fact[20]; int used[20]; bool isLucky(long long int a) { int re...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
from itertools import * n, k = map(int, raw_input().split()) MAXK = 1000000000 LNUMS = [] lc = [ [0], [] ] for i in range(10): idx = i%2 lc[1-idx] = [] for v in lc[idx]: lc[1-idx] += [v*10+4, v*10+7] LNUMS += lc[1-idx] FAC = [1] j = 1 d = 1 while d <= MAXK: j ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { for (int i = 0; i < (1 << 9); i++) { int k = i, n = 0, j = 0; while (k > 0) { if (k % 2 == 1) n = (n * 10) + 7; else n = (n * 10) + 4; k /= 2; j++; } if (n != 0) v.push_back(n); for (;...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; vector<int> a; int aa[20]; void search(int x) { if (x != 0) a.push_back(x); if (x > 100000000) return; search(x * 10 + 4); search(x * 10 + 7); } int islucky(int x) { char tmp[20]; int i, l; sprintf(tmp, "%d", x); l = strlen(tmp); for (i = 0; i < l; i++) ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; bool lucky(int x) { while (x) { if (x % 10 != 4 && x % 10 != 7) break; x /= 10; } if (x == 0) return true; else return false; } int fact(int n) { int x = 1, i; for (i = 1; i <= n; i++) x *= i; return x; } int a[10000], b[100]; int main() { in...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T pow2(T a) { return a * a; } template <class T> inline bool mineq(T& a, T b) { if (a < b) { a = b; return true; } return false; } vector<long long> luck; long long fact[20]; bool islucky(long long n) { while (n) { if (n % 10 ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1E-7; long long lt[10000], tot, fa[15]; long long n, m; int b[20]; void work(int x, long long w, int dp) { if (x == dp) { lt[tot++] = w; return; } work(x + 1, w * 10 + 4, dp); work(x + 1, w * 10 + 7, dp); } bo...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; vector<long long> tail; vector<long long> used; long long n, k; bool isGood(long long x) { while (x > 0) { if (x % 10 != 7 && x % 10 != 4) return false; x /= 10; } return true; } vector<long long> v; int main() { long long i, j; long long x; long long to...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int Len = 2333333; char buf[Len], *p1 = buf, *p2 = buf, duf[Len], *q1 = duf; inline char gc(); inline int rd(); inline void pc(char c); inline void rt(int x); inline void flush(); int n, k, t, K, ans, f[15], p[15]; vector<int> V; inline int check(int x) { while (x) ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ProblemC { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedRe...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; void JIZZ() { cout << ""; exit(0); } const long double PI = 3.14159265358979323846264338327950288; const long double eps = 1e-13; const long long mod = 1e9 + 7; vector<long long> luc; void init() { for (int dg = 1; dg <= 10; ++dg) { for (int i = 0; i < (1 << dg); ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1E9 + 7, INF = 2E18 + 5; const double PI = 2 * acos(0.0); const long double EPS = 1.0E-14; long long arrFact[15]; vector<long long> vecInit, vec; long long n, k, ans; void make_Permutation() { vec.push_back(0); long long ind, per, sz, len; len = ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; inline bool isgood(int a) { while (a) if ((a % 10 != 4) && (a % 10 != 7)) return false; else a /= 10; return true; } inline int countgood(int r) { int ans = 0, b[10]; long long a = 0; for (int i = 0; i < 10; i++) b[i] = 0; for (;;) { int ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; set<long long> Luckys, adads; long long n, k, fact = 1, f = 1, facts[100], ans; bool mark[100]; vector<int> Permutation; bool isLucky(long long n) { while (n) { if (n % 10 != 4 && n % 10 != 7) return 0; n /= 10; } return 1; } void Lucky_Make(long long n, long ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-6; const double PI = acos(-1.0); const int oo = 0x3f3f3f3f; long long read() { long long d, f = 1; char c; while (!isdigit(c = getchar())) if (c == '-') f = -1; d = c ^ '0'; while (isdigit(c = getchar())) d = (d * 10) + (c ^ '0'); retur...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.PrintStream; import java.util.Arrays; import java.util.Scanner; import javax.naming.BinaryRefAddr; public class Main { static class KPermutation { //elementos del arreglo del cual buscaremos cual es la k-esima permutacion long[] elem; int n;//cantidad de elemntos del arreglo long[] fa...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int dx4[5] = {0, -1, 0, 1, 0}; const int dy4[5] = {0, 0, 1, 0, -1}; const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1}; const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1}; const int maxn = 4e5 + 3; const double PI = ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
def lucky(x): s=str(x) return s.count('4')+s.count('7')==len(s) def Gen_lucky(n): if(len(n)==1): if(n<"4"): return 0 if(n<"7"): return 1 return 2 s=str(n) if(s[0]<'4'): return 0 if(s[0]=='4'): return Gen_lucky(s[1:]) if(s[0]<'7...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const long long MAX = 1000000000ll; const long double EPS = 1E-9; const int INF = (int)1E9; const long long INF64 = (long long)1E18; const long double PI = 2 * acos(.0); long long fact[15]; void factorial(int x) { fact[0] = 1; fact[1] = 1; for (int i = 2; i < (int)(x ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int n, k; int s[20], d[20], t[20], r[20]; int a[2000]; void dfs(long long x) { if (x > 1000000000) return; a[++a[0]] = x; dfs(x * 10 + 4); dfs(x * 10 + 7); } int main() { cin >> n; cin >> k; k--; a[0] = 0; dfs(4); dfs(7); a[0] = 2000000000; int x = 1...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int n, k, f[13], p[13]; vector<int> lk; map<int, bool> bea; void gen(int x) { if (x) lk.push_back(x), bea[x] = true; if (x > int(1e8)) return; gen(x * 10 + 4); gen(x * 10 + 7); } int main() { scanf("%d%d", &n, &k); f[0] = 1; for (int i = 1; i <= 12; ++i) f[i] ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int N = 2000010; const int INF = 0x3f3f3f3f; const int mod = 1000000007; const int dir[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, -1, -1, -1, 1, 1, -1, 1, 1}; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long pow...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; /** * Created by IntelliJ IDEA. * User: piyushd * Date: 3/26/11 * Time: 10:53 PM * To change this template use File | Settings | File Templates. */ public class TaskC { long[] fact; void precal() {...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; /** * Author - * User: kansal * Date: 10/27/11 * Time: 8:49 PM */ public class CF91E { public static void main(String[] args) { ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int c(long long a, long long b) { if (a > b) return 0; return 1 + c(a * 10 + 4, b) + c(a * 10 + 7, b); } int is(long long a) { return a == 0 || (a % 10 == 4 || a % 10 == 7) && is(a / 10); } long long f[20]; bool u[20]; int main() { int n, k; cin >> n >> k; k--; ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long a[10005]; int f[20], nums[20], c[20]; int num; int g(int x) { int ret = 0; for (int i = 1; i <= num; i++) if (a[i] <= x) ret++; return ret; } bool lucky(int x) { while (x) { int c = x % 10; if (c != 4 && c != 7) return false; x /= 10; } ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") template <class T> bool scanff(T &ret) { char c; int sgn; T bit = 0.1; if (c = getchar(), c == EOF) return 0; while (c != '-' && c != '.' && (c < '0' || c > '9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long p[20]; int n, k, ans; void pcheck(int num) { char s[20]; int i; sprintf(s, "%d", num); for (i = 0; s[i]; i++) if (s[i] != '4' && s[i] != '7') return; ans++; } void check(long long num) { if (num > n) return; if (n - num > 15) pcheck(num); e...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const long long N = 14; long long n, k, ans, fac[N]; long long get(string &s) { long long res = 0; for (char c : s) res = 10 * res + (long long)(c - '0'); return res; } string get_s(long long x) { string res; while (x) { res += (char)((x % 10) + '0'); x /=...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long fact[20], n, k, anss; vector<int> vec, vec2; long long num(int a) { int j = 0; for (int i = 31; i >= 0; i--) if ((a >> i) & 1) { j = i; break; } long long ans = 0; for (int i = j - 1; i >= 0; i--) { ans *= 10; if ((a >> i) & 1) ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int n, k; int s[20], d[20], t[20], r[20]; int a[2000]; void dfs(long long x) { if (x > 1000000000) return; a[a[2000]++] = x; dfs(x * 10 + 4); dfs(x * 10 + 7); } int main() { cin >> n; cin >> k; k--; a[2000] = 0; dfs(4); dfs(7); int x = 1; s[1] = 1; ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.List; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.util.Collections; import java.io.InputStreamReader; import java.util.ArrayList;...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int N = 210; const int M = 200000; const int K = 510; const long long LIT = 1000000000LL; const int INF = 1 << 30; long long n, k; vector<long long> num; void dfs(long long u) { if (u) num.push_back(u); if (u > LIT) return; dfs(u * 10 + 4); dfs(u * 10 + 7); } ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long inf = 5e18; vector<string> num_string({"4", "7"}); map<long long, int> mp; vector<long long> fact; bool check(long long mid, long long n, long long k) { if (n - mid >= fact.size()) { return false; } else { return fact[n -...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long int fact(long long int n) { if (n == 0) return 1; return n * fact(n - 1); } vector<int> permutacion(int n, int k) { if (n == 1) return vector<int>(1, 1); for (int val = 1; val <= n; val++) { if (val * fact(n - 1) >= k) { vector<int> v = permutaci...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int maxn = 10000 + 1000; const int inf = 1e9; int per[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; bool is_lucky(int x) { while (x) { if (x % 10 != 4 && x % 10 != 7) return 0; x /= 10; } return 1; } long long makelucky(long long x, int l) { long...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int c = 15; int n, k; int r; long long f[c]; vector<int> v; int ans; void go(long long i) { if (i > (long long)n) return; if (i) { if (i <= n - r) ans++; else v.push_back(i); } go(i * 10 + 4); go(i * 10 + 7); } bool b[c]; bool q[c]; int m...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; bool islucky(long long n) { while (n) { if (n % 10 == 4 || n % 10 == 7) { } else return 0; n = n / 10; } return 1; } long long fact(long long k) { long long n = 1; while (k > 1) { n = n * k; k--; } return n; } vector<long long> factor...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:640000000") using namespace std; bool lucky(int x) { for (; x; x /= 10) if (x % 10 != 4 && x % 10 != 7) return false; return true; } unsigned long long luck[] = { 4, 7, 44, 47, 74, 77, 444, 447, 47...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; int n, k; int n1; vector<long long> v; int c[20]; int a[20]; bool viz[20]; int f[20]; inline void get(int i) { int cif = 0; long long zece = 1; long long r = 0; for (zece = 1; i > 0; i >>= 1, zece *= 10LL) { ++cif; if ((i & 1) != 0) r += 7LL * zece; ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long n, k; long long fact[20]; inline long long XF(int x) { return x > 13 ? 10000000000LL : fact[x]; } int L, R; map<int, int> pv; vector<int> avb; int lucky(int w) { while (w) { int T = w % 10; if (T != 4 && T != 7) return 0; w /= 10; } return 1; } i...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.util.*; public class Main { public static long factorial(int n) { long res = 1; for (int i = n; i > 1; i--) res *= i; return res; } private static ArrayList<Integer> res(ArrayList<Integer> v, int k) { ArrayList<Integer> res = new ArrayList<Integer>()...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long n, k, m; long long ed; long long f[20], cur[20], a[20], vis[20]; long long ans = 0; void solve(long long now) { if (now > m) return; ans++; solve(now * 10 + 4); solve(now * 10 + 7); } bool legal(long long x) { while (x > 0) { long long tmp = x % 10; ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
//package round91; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.BitSet; public class C { InputStream is; PrintWriter out; String INPUT = ""; long[] lucky; void solve() { int n = ni(), k = ni(...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const long long LINF = ~(((long long)0x1) << 63) / 2; const int INF = 0X3F3F3F3F; const double eps = 1e-7; const long long limit = 1000000000LL; vector<long long> c; void dfs(long long now) { if (now > limit) return; if (now != 0) c.push_back(now); dfs(now * 10 + 4); ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; void RunProgram(); int main() { RunProgram(); } long long fact[14], k; int n, m, d[20]; bool avail[20]; void MakeD(int n) { memset(avail, true, sizeof(avail)); for (int i = 1; i <= n; i++) { int j; for (j = 1; j <= n; j++) if (avail[j]) if (k > fac...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class C { static List<Integer> luckyNumbers = new ArrayList<Integer>(); static long factorials[] = new long[13]; static void calculateLuckyNumbers(int n , int i){ if(i >= 10) retur...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int intmax = 0x3f3f3f3f; const long long lldmax = 0x3f3f3f3f3f3f3f3fll; double eps = 1e-8; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b;...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long fac[20], n, k; long long answer; void rec(long long x, long long lim) { if (x > lim) return; answer++; rec(10 * x + 4, lim); rec(10 * x + 7, lim); } long long calc(long long lim) { rec(4, lim); rec(7, lim); } long long ohMyLuck(long long x) { while (...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; const int MAXN = 1e4 + 10; const int MOD = 1e9 + 7; const int inf = 1e9; const double pi = acos(-1.0); const double eps = 1e-6; int dx[] = {0, -1, 0, 1}; int dy[] = {1, 0, -1, 0}; long long F[40]; int calc(int l, long long n) { if (n >= l) return...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; set<long long> S; void go(const long long &x, const int &M, const long long &U) { if (x > U) return; if (x > M) S.insert(x); go(10 * x + 4, M, U), go(10 * x + 7, M, U); } bool ok(long long x) { for (; x; x /= 10) { int a = x % 10; if (a != 4 && a != 7) retur...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100099; int n, k; vector<long long> lucky; void gen(long long num) { lucky.push_back(num); if (num > n) return; gen(num * 10 + 4); gen(num * 10 + 7); } vector<int> d; long long precalc[20]; bool used[20]; void findk(int n, int k, int len) { if (le...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long i, j, k, n, m, t, f, x, y, cnt; long long nl, tmp, gcnt, ans; long long luckyNum[20007], fct[16], v[16], ad[16]; queue<long long> qa, qb; set<long long> st; long long findFct(long long n) { i = 0; for (i = 1; i < 16; i++) { if (fct[i] > n) { return i...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.LinkedList; import java.util.Locale; import ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); void gen(vector<int> &nums, long long int x) { if (x > 1000000000) return; if (x > 0) nums.push_back(x); gen(nums, 10 * x + 4); gen(nums, 10 * x + 7); } bool isLucky(int x) { while (x > 0) { if (x % 10 != 4 && x % 10 != 7) return ...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; const int MAXN = -1; long long n, K, pot[20], fact[20], ans; set<long long> luckySet; bool used[20]; long long arr[20]; void kth(int pos, int size, long long k) { if (pos == size + 1) { return; } long long p = 1; while (true) { assert(p <= 20); if (used[...
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how ...
#include <bits/stdc++.h> using namespace std; long long gao(int x, int c) { long long ret = 0, g = 1; for (; c--; g *= 10, x >>= 1) { ret += g * ((x & 1) ? 7 : 4); } return ret; } vector<long long> v; long long fct[16]; int c[16]; bool p[16]; bool lk(int x) { while (x) { if (x % 10 != 4 && x % 10 != 7...