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;
long long jc[14];
long long ans[14];
int n, k;
int vis[14];
void f(long long k, int dep) {
if (dep == 0) {
return;
}
if (jc[dep - 1] > k) {
for (int i = 1; i <= n; i++) {
if (!vis[i]) {
ans[min(n, 13) - dep] = i;
vis[i] = 1;
f(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 findFirstNumIndex(int& k, int n) {
if (n == 1) return 0;
n--;
int first_num_index;
int n_partial_fact = n;
while (k >= n_partial_fact && n > 1) {
n_partial_fact = n_partial_fact * (n - 1);
n--;
}
first_num_index = k / n_partial_fact;
k = k % n_pa... |
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;
map<long long, int> ha;
long long n, m, mm;
int ans;
int a[20], s, vis[20];
long long p[10000];
long long ch[20];
void dfs(int k, long long t) {
long long tt;
if (k == 10) return;
tt = t * 10 + 4;
p[++s] = tt;
ha[tt] = 1;
dfs(k + 1, tt);
tt = t * 10 + 7;
p[+... |
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>
std::vector<long long> generateLuckyNumbers(long long limit) {
std::vector<long long> result;
std::queue<long long> Q;
Q.push(4);
Q.push(7);
while (!Q.empty()) {
long long x = Q.front();
Q.pop();
if (x <= limit) {
result.push_back(x);
Q.push(x * 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 fac[14];
vector<long long> lucky;
bool isLucky(long long n) {
int x;
while (n) {
x = n % 10;
n /= 10;
if (x == 4 || x == 7) continue;
return 0;
}
return 1;
}
void gen(long long n) {
long long x = n * 10;
if (x > 1000000000ll) 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>
const double eps = 1e-9;
const int int_inf = 1 << 31 - 1;
const long long i64_inf = 1ll << 63 - 1;
const double pi = acos(-1.0);
using namespace std;
int n;
long long k;
int res = 0;
int a[20];
int b[20];
long long fac[20];
vector<int> L;
void gen(int a = 0, int len = 0) {
L.push_back(a);
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 ok(long long n, long long k) {
if (n >= 13) return true;
long long r = 1;
for (int i = 0; i < n; i++) r *= (i + 1);
if (r > k) return true;
return false;
}
long long fact(int n) {
if (n >= 13) return 10000000007ll;
long long ret = 1ll;
for (int i = 0; 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.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Com... |
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 = 1e5 + 5;
long long f[15], all[15];
long long n, k;
int solve(int rem) {
if (!rem) return 1;
return solve(rem - 1) * 2;
}
long long solve(int i, string& str) {
if (i == str.size()) return 1;
long long ret = solve(i + 1, str);
if (str[i] == '1') ret +=... |
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 = 1 << 20;
long long fac[20];
vector<long long> lst;
vector<long long> lucky;
void prepare(int cnt, int all, long long now) {
if (cnt == all) {
lucky.push_back(now);
return;
}
prepare(cnt + 1, all, now * 10 + 4);
prepare(cnt + 1, all, now * 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 ... | /**
* Created by IntelliJ IDEA.
* User: Taras_Brzezinsky
* Date: 10/27/11
* Time: 5:55 PM
* To change this template use File | Settings | File Templates.
*/
import sun.misc.Sort;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.FileReader;
import java.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-9;
const double PI = acos(-1.);
template <class T>
inline T sq(T x) {
return x * x;
}
template <class T>
inline void upd_min(T &lhs, T rhs) {
if (lhs > rhs) lhs = rhs;
}
template <class T>
inline void upd_max(T &lhs, T rhs) {
if (lhs < rhs) lhs =... |
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 ... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
new Main().start();
}
private long fact(long m) {
long ret = 1;
for (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 ... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {
static ArrayList<Long> aa;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(),k = in.nextInt();
aa = new Array... |
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 static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
public class Main {
public static void main(String[]args){
new Main().run();
}
private void debug(Object...os){
System.err.println(deepToString(os));
}
private void run() {
Scanner 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 a[100010], fac[20], vis[20], ans1[20], ans;
int n, k, tmp1, tmp2;
void dfs(long long now) {
if (now <= tmp2 && now) {
ans++;
}
if (now >= 1000000000) {
return;
}
dfs(now * 10 + 4);
dfs(now * 10 + 7);
}
void solve(int now) {
if (now > tmp1) {
... |
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 = 200;
vector<long long> luck;
void dfs(long long a, long long len) {
if (len > 11) return;
if (a) luck.push_back(a);
dfs(a * 10 + 4, len + 1);
dfs(a * 10 + 7, len + 1);
}
long long fact[30];
long long arr[50];
void find(long long n, long long 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;
template <typename T>
vector<T> readvector(size_t size) {
vector<T> res(size);
for (size_t i = 0; i < size; ++i) {
cin >> res[i];
}
return res;
}
template <typename T>
void printvector(vector<T>& arr, string sep = " ", string ends = "\n") {
for (size_t i = 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 n, k, f[25];
vector<long long> v, sol;
set<long long> s;
void dfs(long long now) {
if (now > 1000000000) return;
v.push_back(now);
s.insert(now);
dfs(now * 10 + 4);
dfs(now * 10 + 7);
}
void build() {
dfs(4);
dfs(7);
sort(v.begin(), v.end());
f[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 ... | #!/usr/bin/python
import sys
a = []
def gen (n, d):
global a
if n > 0:
a += [n]
if d > 0:
gen (n * 10 + 4, d - 1)
gen (n * 10 + 7, d - 1)
def go (l, r, pos, c):
l = max (l, pos)
r = min (r, c)
# print l, r, c
return max (r - l + 1, 0) * c
def fact (n):
if n > 12:
return 10 ** 9 + 1
if n == 0:
retu... |
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>
long long permu[14];
bool is_used[14];
int permu_pos[14];
long long lucks[2000];
int luck_cnt;
int main() {
long long i, j, k;
int N, K, p1, p2, t1, t2, t3, m = 1e9;
permu[0] = 1;
for (i = 1; i < 14; i++) {
permu[i] = 1;
for (j = 1, k = 1; j <= i; j++) permu[i] *= j;
}
luck_... |
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, i, j, Length, result, a[30];
queue<long long> q, q2;
bool check[30];
bool Lucky(long long x) {
while (x > 0) {
if (x % 10 != 4 && x % 10 != 7) return false;
x /= 10;
}
return true;
}
void process() {
long long t, t2;
q2.push(4);
q2.push(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;
long long fact[20];
int offset[20];
int vals[20];
vector<int> lidx;
bool islucky(int x) {
while (x > 0) {
if (x % 10 != 4 && x % 10 != 7) return false;
x /= 10;
}
return true;
}
int main() {
fact[0] = fact[1] = 1;
for (int i = 2; i < 20; i++) fact[i] = (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>
using namespace std;
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
auto lucky_check = [&](long long x) {
while (x) {
if (x % 10 != 4 and x % 10 != 7) return false;
x /= 10;
}
return true;
};
vect... |
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 Main {
public static void main ( String args[] ) throws Exception {
(new Task23()).solve();
}
}
class Task23
{
Scanner in;
int[] getPermutation ( int[] a, long k )
{
boolean seen[] = new boolean[a.length];
int r[] = new int[a.length];
Arrays.fill ( r, ... |
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<unsigned long long> luck;
unsigned long long f[15];
vector<unsigned long long> v;
int L;
set<unsigned long long> S;
void build() {
int cnt = 2;
luck.push_back(4);
luck.push_back(7);
for (int i = 2; i <= 9; ++i) {
int p = ((int)luck.size());
for (int w... |
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 ArrayList<Long> aa;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
aa = new ArrayList<Long>(2500)... |
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 sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
if (n < 13) {
if (k > fac(n)) {
System.out.println(-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;
const long long maxn = 1e5 + 10, maxe = 15;
long long n, k, x, ans = -1;
long long fact[maxe], A[maxe], use[maxe];
void lucky_generator(long long a) {
if (a > x) return;
ans++;
lucky_generator(a * 10 + 4);
lucky_generator(a * 10 + 7);
}
bool is_lucky(long long a) {
... |
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, num = 0, co = 0, tempo[16], tag[17];
long long temp[10001], K, dp[16], ans[16];
void DFS(long long now) {
if (now > N) {
temp[num++] = now;
return;
}
temp[num++] = now;
DFS(now * 10 + 4);
DFS(now * 10 + 7);
}
int Check(long long key) {
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;
long long P[2000], sz, Ans, N, K;
long long Q[10000];
int size;
void Dfs(int k, long long s) {
Q[++size] = s;
if (k == 11) {
return;
}
Dfs(k + 1, s * 10 + 4);
Dfs(k + 1, s * 10 + 7);
}
void Init() {
Dfs(1, 0);
sort(Q + 1, Q + size + 1);
}
long long Fac(lon... |
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 = 1e9 + 10;
const long long int INFLL = 1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-14;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
return a = min(a, b);
}
template <class T>
T &chmax(T &a, con... |
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 ga(int N, int *A) {
for (int i(0); i < N; i++) scanf("%d", A + i);
}
long long f[(20) + 1] = {1};
int C[26], X;
char s[666], r[666];
void nth(long long K, char *o, char *s) {
if (!X++)
for (int k(1); k < (20) + 1; k++) f[k] = f[k - 1] * k;
long long L(strlen(... |
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:256777216")
using namespace std;
long long num[10000];
int nn = 0;
long long fact[] = {1, 1, 2, 6, 24,
120, 720, 5040, 40320, 362880,
3628800, 39916800, 479001600, 6227020800... |
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.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Collection;
import java.io.InputStream;
/*... |
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;
map<long long int, bool> mp;
int N, sayi = 1, dizi[20], ekle, mark[20], T, end = 0, Q, bsmk, sayac;
long long int K, carp = 1, carp2 = 1;
int bul(int X) {
int T = 0;
for (int i = 1; i <= Q; i++) {
if (!mark[i]) T++;
if (T == X) return i;
}
}
void 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 ... | import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Set;
... |
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> lucky;
void gen(long long g, long long lim) {
if (g + 4 > lim)
return;
else
lucky.insert(g + 4);
gen(10 * (g + 4), lim);
if (g + 7 > lim)
return;
else
gen(10 * (g + 7), lim);
lucky.insert(g + 7);
}
bool check(long long num) {
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.*;
public class LuckyPermutation {
public static void main (String [] arg) {
Scanner sc = new Scanner(System.in);
long N = sc.nextInt();
long K = sc.nextInt()-1;
boolean overflow = (N > 15);
int [] P = (overflow) ? permutation(15, K) : permutation((int)N,K);
if (P == null) { System.out.... |
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.*;
import java.util.Random;
import static java.lang.Math.*;
public class Solution implements Runnable {
public static void main(String[] args) throws Exception {
new Thread(null, new Solution(), "", 1 << 25).start();
}
BufferedReader in;
PrintWriter out;
... |
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> lucky, f;
vector<int> u;
long long n, k;
void dfs(long long v) {
if (v > 7777777777LL) return;
if (v) lucky.push_back(v);
dfs(v * 10 + 4);
dfs(v * 10 + 7);
}
int main() {
dfs(0);
sort(lucky.begin(), lucky.end());
f.push_back(1);
cin >> 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;
inline void read(register int *n) {
register char c;
*n = 0;
do {
c = getchar();
} while (c < '0' || c > '9');
do {
*n = c - '0' + *n * 10;
c = getchar();
} while (c >= '0' && c <= '9');
}
vector<int> kperm(vector<int> V, long long k) {
k--;
vect... |
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 std::cin;
using std::cout;
using std::endl;
using std::min;
using std::string;
using std::vector;
long long next(long long x) {
if (x == 0) return 0;
if (x % 10 <= 4) {
long long a = next(x / 10);
return a * 10 + 4;
}
if (x % 10 <= 7) {
long long a = next(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 sys
from math import factorial
def kth_perm(seq, index):
result = []
fact = factorial(len(seq))
index %= fact
while seq:
fact = fact / len(seq)
choice, index = index // fact, index % fact
result.append(seq.pop(choice))
return result
def inc_lucky(s, index):
if index == -1:
s = ['4'] + s
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 ... | L = [4,7,44,47,74,77,444,447,474,477,744,747,774,777,4444,4447,4474,4477,4744,4747,4774,4777,7444,7447,7474,7477,7744,7747,7774,7777,44444,44447,44474,44477,44744,44747,44774,44777,47444,47447,47474,47477,47744,47747,47774,47777,74444,74447,74474,74477,74744,74747,74774,74777,77444,77447,77474,77477,77744,77747,77774,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 ... | import static java.lang.Math.*;
import java.util.*;
import java.io.*;
public class E {
public void solve() throws Exception {
int n = nextInt(), k = nextInt()-1;
if (n<=12 && k>=facArr[n]) halt(-1);
HashSet<Integer> hs = new HashSet<Integer>();
dfs(4,hs); dfs(7,hs);
int l... |
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;
long long fact[14] = {1};
bool cmp(int p) {
if (p > 13 || fact[p] >= k) return true;
k -= fact[p];
return false;
}
bool check(int x) {
while (x) {
if (x % 10 != 4 && x % 10 != 7) return false;
x /= 10;
}
return true;
}
bool used[16];
int s;
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;
const int maxn = 1e6 + 7;
const long long mod = 998244353;
const long long INF = 5e18 + 7;
const int inf = 1e9 + 7;
const long long maxx = 1e6 + 700;
long long n, k;
long long fac[maxn];
vector<int> v;
int ans = 0;
int find(int x) {
sort(v.begin(), v.end());
int t = v[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;
map<int, bool> mp;
map<int, bool>::iterator it;
long long p[1 << 11] = {0}, psum = 1;
long long q[20];
bool flag[20];
void Init() {
mp.clear();
memset(flag, 0x00, sizeof(flag));
for (int i = 0; i < psum; i++) {
if (p[i] < 1e9) {
p[psum++] = p[i] * 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;
const long long MAXN = 1e6 + 1, mod = 1e9 + 7, INF = 1e9 + 10;
const double eps = 1e-9;
template <typename A, typename B>
inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B>
inline bool chmax(A &a, B 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 rev(long long t) {
long long res = 0;
while (t) {
if (t % 2)
res *= 10, res += 7;
else
res *= 10, res += 4;
t /= 10;
}
return res;
}
long long conv(long long t, int len) {
long long res = 0, ans = 0, k = 0;
while (t) {
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[10000], jc[20];
int t, o[20], p[20];
int cal(long long x) {
if (x <= 0) return 0;
int ans = 0;
for (int i = (1); i <= (t); i++)
if (a[i] <= x)
ans++;
else {
break;
};
return ans;
}
void init() {
t = 0;
for (int i = (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.*;
import java.io.*;
import java.math.BigInteger;
import static java.lang.Math.*;
public class Main implements Runnable {
private void solution() throws IOException {
int n = in.nextInt();
int k = in.nextInt();
if (fact(n) < k) {
out.println(-1);
} else {
long res = 0;
if (n <= 15) {... |
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> lucky;
long long l, r;
void gen(long long x) {
if (x >= 4444444444ll) return;
lucky.push_back(x);
gen(x * 10 + 4);
gen(x * 10 + 7);
}
bool islucky(int x) {
if (!x) return (false);
while (x) {
if (x % 10 != 4 && x % 10 != 7) return (false);
... |
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 file_open() {
freopen("test.txt", "rt", stdin);
freopen("test.out", "wt", stdout);
}
bool check(unsigned long long x) {
while (x) {
if (x % 10 != 7 && x % 10 != 4) return false;
x /= 10;
}
return true;
}
void swap(int &a, int &b) {
int tmp = a;
a ... |
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.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;
public class Solution121C {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok... |
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 <typename X>
ostream& operator<<(ostream& x, const vector<X>& v) {
for (long long i = 0; i < v.size(); ++i) x << v[i] << " ";
return x;
}
template <typename X>
ostream& operator<<(ostream& x, const set<X>& v) {
for (auto it : v) x << it << " ";
return 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.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
/**
* Created by IntelliJ IDEA.
* User: serparamon
* Date: 27.10.11
* Time: 18:39
* To change this template use File | Settings | File Templates.
*/
public class Contest20111027_C {
... |
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-9;
long long perm[18];
set<long long> lu;
void gen_luck(long long x) {
if (x > 100000000000LL) return;
lu.insert(x);
gen_luck(x * 10LL + 4LL);
gen_luck(x * 10LL + 7LL);
}
int sz;
bool ud[21];
vector<int> res, val;
void get_res(int x, int 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;
vector<int> lucky;
void init() {
lucky.push_back(0);
for (size_t i = 0; i < lucky.size(); i++) {
if (lucky[i] >= 100000000) break;
lucky.push_back(lucky[i] * 10 + 4);
lucky.push_back(lucky[i] * 10 + 7);
}
lucky.erase(lucky.begin());
}
bool islucky(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;
long long lucky[1024 * 4];
long long fact[14];
int cnt;
void func(long long cur, int pos, int maxpos) {
if (pos == maxpos) {
lucky[++cnt] = cur * 10 + 4;
lucky[++cnt] = cur * 10 + 7;
return;
}
func(cur * 10 + 4, pos + 1, maxpos);
func(cur * 10 + 7, pos +... |
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 F[15];
vector<long long> p;
void dfs(long long c, long long mx) {
if (c > mx) return;
if (c) p.push_back(c);
dfs(10 * c + 4, mx);
dfs(10 * c + 7, mx);
}
int main() {
F[0] = 1;
for (int i = 1; i < 15; i++) F[i] = F[i - 1] * i;
cin >> 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 ... | import java.util.*;
public class Main {
public static void main(String args[]) {
(new Main()).solve();
}
int solve(int n, int k) {
int last = 1;
long perm = 1;
while( k > perm ) {
++last;
perm *= last;
}
if( last > n ) { return - 1; }
int ret = count(n - last);
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 k;
int n;
vector<long long> v;
long long fact[15];
bool esta[20];
map<long long, bool> es;
void go(long long num, int pos) {
if (pos > 11) return;
v.push_back(num);
go(num * 10 + 4, pos + 1);
go(num * 10 + 7, pos + 1);
}
vector<int> get_permutation(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 countbit(int n) { return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); }
int lowbit(int n) { return (n ^ (n - 1)) & n; }
const double pi = acos(-1.0);
const double eps = 1e-11;
long long p[20];
int N, K;
vector<int> path;
vector<long long> lucky;
int exist;
void proc(vect... |
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 bound[15];
int n, k, ans;
long long lucky[3000];
int num;
void dfs(long long x, int pos) {
long long c1 = x * 10ll + 4ll, c2 = x * 10ll + 7ll;
if (pos <= 10) {
lucky[num++] = c1;
lucky[num++] = c2;
dfs(c1, pos + 1);
dfs(c2, pos + 1);
}
}
int main()... |
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_N = 15 + 5;
long long fact[MAX_N] = {1};
bool mark[MAX_N];
int a[MAX_N];
void Permutation(int k, int id) {
if (id == 15) return;
int x = (k - 1) / fact[14 - id];
k -= x * fact[14 - id];
for (int i = 0; i < 15; i++) {
if (!mark[i] && x)
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;
std::vector<long long> v;
long long c(long long i) {
while (i) {
if (i % 10 == 4 || i % 10 == 7) {
} else
return 0;
i /= 10;
}
return 1;
}
long long MAXN = 1e10;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(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.LinkedList;
import java.util.List;
import java.util.Scanner;
public class luckPerm {
public static void debug(Object... obs) {
System.out.println(Arrays.deepToString(obs));
}
public static void main(String[] args) throws Ex... |
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 C121 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
if (n < 13) {
if (k > fac(n)) {
System.out.println(-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.lang.*;
import java.awt.geom.Line2D;
import java.io.*;
import java.util.*;
import java.math.*;
public class C implements Runnable{
ArrayList<Integer> ns;
HashSet<Integer> h;
private void rec(long cur, int max) {
if (cur >= max) {
return;
}
if (cur >... |
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 = 1e6 + 11;
const long long MOD = 1e18;
long long n, k;
int ans = 0;
vector<long long> vv;
bool good(long long c) {
while (c > 0) {
if (c % 10 == 4 || c % 10 == 7) {
} else
return false;
c /= 10;
}
return true;
}
void dfs(long long l) {
... |
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.*;
//created at 7:48 PM 10/27/11 by Abrackadabra
public class C {
int IOMode = 0; //0 - consoleIO, 1 - <taskName>.in/out, 2 - input.txt/output.txt, 3 - test case generator
String taskName = "";
int l, n;
int[] a;
long[] f;
void solve() t... |
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];
vector<int> v;
vector<int> nthPerm(vector<int>& identity, int nth) {
vector<int> perm(identity.size());
int len = identity.size();
for (int i = identity.size() - 1; i >= 0; i--) {
int p = nth / Fact[i];
perm[len - 1 - i] = identity[p];
... |
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>
bool DEBUG = false;
using namespace std;
int val[5000];
int l, cur, n, k, result;
int sel[15], sl, perm[15];
bool used[15];
int fact[13], os;
int main() {
l = 0;
val[l++] = 4;
val[l++] = 7;
cur = 0;
while (l < 1000) {
int tmp = l;
for (int i = (cur); i < (tmp); ++i) {
va... |
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-11;
const int inf = 0x7FFFFFFF;
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;
}
template <class T>
inline T sqr(T 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;
template <class T>
T _abs(T n) {
return (n < 0 ? -n : n);
}
template <class T>
T _max(T a, T b) {
return (!(a < b) ? a : b);
}
template <class T>
T _min(T a, T b) {
return (a < b ? a : b);
}
template <class T>
T sq(T x) {
return x * x;
}
const double EPS = 1e-9;
con... |
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 = 20 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;
double eps = 1e-8;
template <class T>
T QuickMod(T a, T b, T c) {
T ans = 1;
while (b) {
if (b & 1) ans = ans * a % c;
b >>= 1;
a = (a * a) % c;
}
return ans;
}
template <class T>
T Gcd(T a, T 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;
inline void OPEN(const string &file_name) {
freopen((file_name + ".in").c_str(), "r", stdin);
freopen((file_name + ".out").c_str(), "w", stdout);
}
long long fact[50];
inline void initfact() {
fact[0] = 1;
for (int i = (1), _b = (49); i <= _b; i++) fact[i] = fact[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 N;
long long K;
long long F[12];
vector<long long> S;
void DFS(int a) {
if (a > 10) {
long long res = 0, flag = 0;
for (int i = 1; i <= 10; i++) {
if (F[i] == 0) {
if (flag) return;
} else if (F[i] == 1) {
res = res * 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 ... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
public class HappyPermutation implements Runnable {
private void solve() throws... |
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 math
def good(x):
while x > 0:
if x % 10 != 4 and x % 10 != 7:
return False
x //=10
return True
n, k = map(int, input().split())
l = 1
r = n
if n >= 15:
l = n-14
if n <= 15 and math.factorial(n) < k:
print(-1)
else:
L = r - l + 1
a = []
for i in range(L)... |
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 p[11];
bool used[15];
long long f[15];
vector<int> g;
bool is_good(long long x) {
if (x < 4) return false;
while (x > 0) {
if (x % 10 != 4 && x % 10 != 7) return false;
x /= 10;
}
return true;
}
int main() {
int n, ans = 0;
long long k;
cin >> 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 ... | import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
BufferedReader in;
StringTokenizer st;
PrintWriter out;
static ArrayList<Long> list = new ArrayList<Long>();
static void gen(long a, int len) {
// if (a != 0)
list.add(a);
if (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;
const int N = 14;
vector<int64_t> fact(N, 1);
vector<int64_t> happies;
vector<int> k_perm(int64_t n, int64_t k) {
--k;
vector<int> a(n);
vector<bool> used(n + 1);
for (int i = 0; i < n; ++i) {
int64_t alreadyWas = k / fact[n - i - 1];
k %= fact[n - 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.util.*;
public class EPerm {
static int[] factorial = {-1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600};
static long[] luckyNums = new long[1024];
static HashSet<Long> theNums = new HashSet<Long>(5000);
static int[] luckyList = {4, 7};
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;
long long n, k;
vector<long long> perm;
bool used[20];
string hf = "4";
int ans;
bool ish(long long q) {
while (q > 0) {
if (q % 10 != 4 && q % 10 != 7) return false;
q /= 10;
}
return true;
}
long long ltoa() {
long long ten = 1;
long long ta = 0;
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;
map<long long, int> lucky;
void func(long long num) {
if (num > 1000000007) return;
if (num > 0) {
lucky[num] = 1;
}
func(num * 10 + 4);
func(num * 10 + 7);
}
int main() {
func(0);
vector<long long> fact(21);
fact[0] = 1;
for (int i = 1; i < 21; 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 fac[1000000];
long long recursive(long long zxcv, long long hi) {
if (zxcv >= hi) return 0;
return 1 + recursive(zxcv * 10 + 4, hi) + recursive(zxcv * 10 + 7, hi);
}
int main() {
long long n, k;
cin >> n >> k;
long long d = 1;
fac[0] = 1;
for (long l... |
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 signed long long Infinity = 1000000001;
const long double Pi = 2.0L * asinl(1.0L);
const long double Epsilon = 0.000000001;
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
return os << "(" << p.first << "," << p.second << ")";
}
t... |
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 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 ans, n, k, m, x;
long long fac[15];
int num[15];
bool mark[15];
void dfs(int i = 0, long long num = 0) {
if (num && num <= m) ans++;
if (i == 9) return;
dfs(i + 1, num * 10 + 4);
dfs(i + 1, num * 10 + 7);
}
void make(int i = 1) {
if (i > x) return;
int j = 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;
long long fact[14] = {1};
bool cmp(int p) {
if (p > 13 || fact[p] >= k) return true;
k -= fact[p];
return false;
}
bool check(int x) {
while (x) {
if (x % 10 != 4 && x % 10 != 7) return false;
x /= 10;
}
return true;
}
bool used[16];
int s;
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;
string lower(string s) {
for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
return s;
}
vector<string> sep(string s, char c) {
string temp;
vector<string> res;
for (int i = 0; i < s.size(); i++) {
if (s[i] == c) {
if (temp != "") res.push_back(temp... |
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[] = {1, 1, 2, 6, 24, 120, 720,
5040, 40320, 362880, 3628800, 39916800, 479001600};
int a[10010];
vector<int> b;
void dfs(long long x) {
if (x >= 1000000000) return;
a[++a[0]] = int(x);
dfs(x * 10 + 4);
dfs(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 static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;
public class C implements Runnable
{
String file = "input";
boolean TEST = false;
void solve() throws IOException
{
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 ... | from math import factorial
import sys
def lucky(x):
return str(x).count('4')+str(x).count('7')==len(str(x))
def fun(x):
xs, result = str(x), 0
for i in range(len(xs)):
rest = 1<<(len(xs)-i-1)
if int(xs[i]) == 4:
continue
elif int(xs[i]) == 7:
result += rest
continue
elif int(xs[i]) < 4:
return ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.