description stringlengths 35 9.39k | solution stringlengths 7 465k |
|---|---|
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;
p... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
public static void main(String[] args) {
new Thread(null, new Main(), "", 256 * (1L << 20)).start();
}... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class ele2 {
public static void debug(Obje... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B_120 {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
// TODO Auto-generated m... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.util.*;
public class QuizLeague {
static boolean[] quiz;
static int n, k;
public static void main(String[] args) throws IOException {
//BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedReader in = new BufferedReader(new FileReader("input.txt"));
... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... |
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class QuizLeague {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new FileReader("input.txt"));
BufferedWriter out... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.util.*;
public class Problem implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer str;
private void solve() throws IOException
{
str = new StringTokenizer(in.readLine());
int n = Integer.parseInt(str.nextToken());
int k = Integer.parseIn... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B {
private void Problem() throws IOException {
int n = nextInt(), k = nextInt(), a[] = new int[n+1];
for (int i = 1; i < n + 1;... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.util.Scanner;
public class quiz
{
public static void main(String args[])throws Exception
{
FileInputStream fs=new FileInputStream("input.txt");
DataInputStream in=new DataInputStream(fs);
String s=in.readLine(),s1=in.readLine();
Scanner sc=new Scanner(s);
int n=sc.nextInt();
int k=sc.nextI... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class Main {
/////////////////////////////////////////////////////////////////
// IO
////////////////////... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
PrintWriter pr = new PrintWriter(new FileOutputStream(new File("output.txt")),true);
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.File;
import java.io.PrintWriter;
import java.lang.*;
import java.util.*;
public class Abhishek {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = sc.... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class P1 {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class _1057QuizLeague {
public static void main(String[] args) throws IOException {
File f = new File("input.txt");
BufferedReader ... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | 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 B implements Runnable
{
String file = "input";
boolean TEST = false;
void solve() throws IOException
{
int n =... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
public class Main{
static class Run implements Runnable{
//TODO parameters
final boolean consoleIO = false;
final String inFile = "input.txt";
final String out... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.util.*;
import java.math.*;
import java.io.*;
public class LOL {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(new File("input.txt"));
PrintStream out = new PrintStream(new File("output.txt"));
int N = in.nextInt();
int K = in.nextInt(... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.util.*;
public class Main {
Scanner in;
PrintWriter out;
void solve() {
int n = in.nextInt();
int k = in.nextInt() - 1;
int[] a = new int[2 * n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
a[i + n] = a[i];
... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
//joutf.close();
public class TaskB {
public static void main(String[] args) throws Exception {
... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
public class B {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("input.txt"));
PrintWriter pw = new PrintWriter(new BufferedWri... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... |
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class Main{
public static void main(String[]args){
InputStream in = System.in;
PrintWriter out = new PrintWriter(System.out);
try{
... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.util.*;
public class test {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int size = sc.nextInt();
int start = sc.nextInt()-1;... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.math.*;
import java.util.*;
import static java.lang.Math.*;
public class problemB implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
public static void main(String[] args) throws Exception {
new Thread(new problemB()).start();
}
private String next() ... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.util.*;
public class Solution
{
public static void main(String args[]) throws Exception
{
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = in.nextInt();
int k = in.nextInt();
int a[] = new int[n + 1];
for(i... |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | import java.io.*;
import java.util.*;
import java.math.*;
public class Main implements Runnable {
private BufferedReader in;
private PrintWriter out;
private StringTokenizer st;
private Random rnd;
public void solve() throws IOException {
int n = nextInt(), k = nextInt() - 1;
int[] a = new int[n];
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 ... | import java.awt.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.List;
import java.util.Queue;
import static java.lang.Math.max;
import static java.lang.Math.min;
public class C implements Runnable{
// SOLUTION!!!
// HACK ME PLEASE IF YOU CA... |
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 oo = 0x3f3f3f3f;
const double eps = 1e-9;
vector<int> lucky;
void generate(long long n) {
if (n > 1000000000LL)
return;
else {
generate(n * 10 + 4);
generate(n * 10 + 7);
if (n > 0) lucky.push_back(n);
}
}
void unrank(vector<int> &perm, 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 N, K, A[14 + 1];
int u[14 + 1];
long long fact[2 * 14 + 1];
vector<long long> all_lucky;
void gen_lucky(int x, int len) {
if (len == 9) {
all_lucky.push_back(x);
return;
}
if (len >= 1) {
all_lucky.push_back(x);
}
gen_lucky(x * 10 + 4, len + 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, N;
int fact[13], p[13], a[13];
int first(int n) {
queue<long long> q;
q.push(0);
int res = -1;
while (q.front() <= 1LL * n) {
long long cur = q.front();
res++;
q.pop();
q.push(10 * cur + 4);
q.push(10 * cur + 7);
}
return res;
}
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 long double PI = 3.14159265358979323;
const long long int linf = 1000111000111000111LL;
const long long int inf = 1011111111;
const long long int N = 100005;
vector<long long int> v1[10], v2;
set<long long int> st2;
int32_t main() {
ios::sync_with_stdio(false);
ci... |
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[3000], cnt;
void dfs(long long now) {
if (now > 1000000000) return;
if (now) lucky[cnt++] = (int)now;
dfs(now * 10 + 4);
dfs(now * 10 + 7);
}
long long fact[20];
int n, m, num[20];
bool flag[20];
int find(int k) {
for (int i = 1;; i++) {
if (!flag[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 fact[15];
vector<long long> luckies;
long long next(int x) {
return *lower_bound(luckies.begin(), luckies.end(), x);
}
long long to_lucky(int x, int l) {
long long res = 0;
for (int i = 0; i < (l); ++i)
if (x & (1 << i))
res = res * 10 + 4;
els... |
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 main() {
int n, k, count = 0, ch = 0, c = 0;
int mas[15] = {1, 2, 6, 24, 120, 720,
5040, 40320, 362880, 3628800, 39916800, 479001600};
int isp[1000] = {}, dl = 0;
long long int mas2[1030] = {
4, 7, 44,... |
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];
long long int perm[13];
set<long long int> lucky;
void genfact() {
fact[0] = 1;
for (long long int i = 1; i < 14; ++i) fact[i] = i * fact[i - 1];
}
void genperm(long long int n, long long int k) {
list<long long int> a;
n = min(n, 13ll);
fo... |
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 t[1500], n, k;
long long fac[20], base, tmp, rec[20], Ans;
bool used[20];
void init(long long x) {
if (x > 1e8) return;
t[++t[0]] = x * 10 + 4;
init(x * 10 + 4);
t[++t[0]] = x * 10 + 7;
init(x * 10 + 7);
}
bool check(long long x) {
for (long long 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;
template <class T>
T abs(T x) {
return x > 0 ? x : (-x);
}
template <class T>
T sqr(T x) {
return x * x;
}
vector<long long> gen() {
vector<long long> res;
for (int len = 1; len <= 11; ++len)
for (int mask = 0; mask < (1 << len); ++mask) {
long long 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;
long long fac[15];
vector<int> getKthPerm(vector<int> arr, long long k) {
if (k == 1) return arr;
int n = arr.size();
for (int i = 1; i <= n; i++) {
if (k <= fac[n - 1] * i) {
vector<int> brr;
for (int j = 0; j < n; j++) {
if (j + 1 == i) conti... |
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, kk, ans, a[15];
long long ci[15];
bool ok;
bool check(int i) {
while (i) {
if ((i % 10 != 4) && (i % 10 != 7)) return false;
i = i / 10;
}
return true;
}
int cal(int r) {
long long now = 0;
int ans = 0, a[11] = {0};
while (now < r) {
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;
const int MAX = 20;
int n;
long long int k, fat[MAX], tmp[MAX];
vector<long long int> lk;
int lucky(long long int x) {
while (x > 0LL) {
long long int a = (x % 10LL);
if (a != 4LL && a != 7LL) return 0;
x /= 10LL;
}
return 1;
}
void lk_gen(int pos) {
if ... |
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 = 1e5 + 50;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int n, k;
int fac[15] = {1, 1, 2, 6, 24, 120, 720,
5040, 40320, 362880, 3628800, 39916800, 479001600};
int Hash[20], p[20];
vector<long long> V;
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;
void CalcLucky(long long num, long long limit) {
long long temp4;
temp4 = num * 10 + 4;
long long temp7;
temp7 = num * 10 + 7;
v.push_back(temp4);
v.push_back(temp7);
if (temp4 <= limit) CalcLucky(temp4, limit);
if (temp7 <= limit) CalcL... |
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.* ;
public class Main {
public static void main(String[] args) {
new Main().solveProblem();
out.close();
}
static Scanner in = new Scanner(new InputStreamReader(System.in));
static PrintStream 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;
int n, m, p;
long long fac[30];
long long Pow[30];
long long who[30];
int v[30];
set<long long> Set;
set<int> Hash;
void dfs(int dep, long long now) {
if (dep < 0) {
Set.insert(now);
return;
}
dfs(dep - 1, now + Pow[dep] * 4);
dfs(dep - 1, now + Pow[dep] * 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 bigmod(long long b, long long p) {
if (p == 0) return 1;
long long my = bigmod(b, p / 2);
my *= my;
my %= 1000000007;
if (p & 1) my *= b, my %= 1000000007;
return my;
}
int setb(int n, int pos) { return n = n | (1 << pos); }
int resb(int n, int 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;
const int N = 4e3 + 5;
const long long mod = 1e9 + 7;
long long power(long long a, long long b, long long c) {
long long ret = 1;
while (b > 0) {
if (b % 2 == 1) ret = (ret * a) % c;
b /= 2;
a = (a * a) % c;
}
return ret;
}
int fact[13];
vector<int> valu... |
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 = 2005;
long long is_luck[N];
long long permu[20];
int get_luck();
int get_permu(long long, long long, long long, long long);
bool judge_luck(long long);
int main() {
long long n, m, res = 0;
cin >> n >> m;
int cnt = 0;
cnt = get_luck();
long long rema... |
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.lang.reflect.Array;
import java.util.*;
public class Main {
static BufferedReader newInput() throws IOException {
return new BufferedReader(new InputStreamReader(System.in));
}
static PrintWriter newOutput() throws IOException {
return new PrintWriter(System.ou... |
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 javax.sound.sampled.Line;
import java.awt.Point;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import static java.math.BigInteger.*;
import java.math.MathContext;
import java.util.*;
public class C{
void testIt()
... |
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, num = 1;
long long kol = 1, RES = 0;
vector<int> mas, other;
vector<int> all;
int main() {
cin >> n >> k;
long long num = 4;
while (num <= n) {
all.push_back(num);
string s = "";
int nn = num;
while (nn) {
if (nn % 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 double pi = acos(-1.0);
vector<long long> a;
int main() {
for (int _b = (10), len = (1); len <= _b; len++)
for (int mask = 0, _n = (1 << len); mask < _n; mask++) {
long long x = 0;
for (int i = (len)-1; i >= 0; i--)
x = x * 10 + ((mask & (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;
struct FenwickT {
long long t[2100];
void add(long long i, long long val) {
for (; i < 2100; i += ((i) & (-i))) t[i] += val;
}
long long query(long long i) {
long long sol = 0;
for (; i > 0; i -= ((i) & (-i))) sol += t[i];
return sol;
}
};
struct F... |
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.LinkedList;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class LuckyPermutation {
static class Scanner{
BufferedReader br=null;
StringTokenizer tk=null;
public Scanner(){
br=... |
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 GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native")
using namespace std;
long long n, k, cnt, i, f[20] = {1, 1}, j;
vector<long long> vec, rem;
set<long long> luck;
void gen(long long n, long long tot) ... |
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 ans = 0;
long long fac[30];
map<int, bool> M;
bool checklucky(long long x) {
for (; x; x /= 10)
if (x % 10 != 4 && x % 10 != 7) return 0;
return 1;
}
int check(int cur) {
if (cur < max(n - 20 + 1, 1)) return checklucky(cur);
int tmp = k;
M.clear(... |
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[22] = {1};
vector<int> solve(int n, long long k) {
int i, j, r;
vector<int> ans;
set<int> st;
for (i = n - 1; i >= 0; i--) {
int t = (k - 1) / fact[i] + 1;
k -= (t - 1) * fact[i];
r = 0;
for (j = 1; j <= n; j++)
if (st.find(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 long long maxn = 14;
long long f[maxn];
long long n, k, ANS;
vector<long long> ans;
vector<long long> v, p;
bool is(long long a) {
while (a) {
if (a % 10 != 4 && a % 10 != 7) {
return false;
}
a /= 10;
}
return true;
}
int32_t main() {
cin >>... |
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 SQ = 100000;
const long long MAXN = SQ * SQ;
long long fact[100];
void init() {
fact[0] = 1;
for (long long i = 1; fact[i - 1] < MAXN; i++) fact[i] = fact[i - 1] * i;
}
long long p[100];
void k_perm(long long n, long long k) {
k--;
for (long long 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;
vector<long long> sil(14);
vector<long long> lucky;
set<long long> luckyS;
void gen() {
for (int i = 1; i <= 10; ++i) {
for (int j = 0; j < (1LL << i); ++j) {
long long x = 0;
for (int k = 0; k < i; ++k) {
if ((j & (1LL << k)) > 0)
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;
vector<int> lucky_nums;
vector<int> datos;
vector<long long> factorial;
set<long long> numeros;
int idx_cambio;
void obten_lucky(int n) {
numeros.insert(0);
for (int i = 0; i < 10; ++i) {
set<long long> temp = numeros;
for (const auto& act : temp) {
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 long long inf = 1000ll * 1000 * 1000;
const int size = 100;
long long smb, n, k;
int ans;
bool used[size];
int perm[size];
void genthemall(long long num) {
if (num > inf) return;
if (num <= n - 15 && num >= 1) ans++;
genthemall(num * 10 + 4);
genthemall(num * ... |
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 d {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int n = input.nextInt(), k = input.nextInt();
if(n < 15)
{
long f = 1;
for(int i = 2; i<=n; i++) f *= i;
if(f < k)
{
System.out.println(-1);
return;
}
}
findLucky();
int rest = 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 ... | F = [1];
while len(F) <= 13:
F.append(F[-1]*len(F));
def get_perm(k,S):
if k >= F[len(S)]:
print -1;
exit(0);
P = [];
while k:
i = 0;
while F[len(S)-1]*(i+1) <= k:
i += 1;
k -= F[len(S)-1]*i;
P.append(S[i]);
S.pop(i);
P += S;
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;
template <class T>
void pv(ostream &out, T a, T b) {
for (T i = a; i != b; ++i) {
out << *i << " ";
}
out << endl;
}
template <class T>
void pvp(ostream &out, T a, T b) {
for (T i = a; i != b; ++i) {
out << "(" << i->first << ", " << i->second << ") ";
}
... |
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.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
imp... |
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 MAX_FACT = 14;
int N, K;
long long fact[MAX_FACT];
int countLucky(long long val, int n) {
int sol = 0;
if (val <= n) {
if (val > 0) ++sol;
sol += countLucky(val * 10 + 4, n);
sol += countLucky(val * 10 + 7, n);
}
return sol;
}
bool isLucky(int val) {
do {
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;
long long fact[20];
int permutation[20];
vector<int> canUse;
int luckySmaller(int n) {
queue<long long> q;
while (!q.empty()) q.pop();
q.push(0);
int ans = 0;
while (!q.empty()) {
long long f = q.front();
q.pop();
long long a[2] = {f * 10 + 4, f * 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 long long N = 14, LIM = 5e9;
vector<long long> vec, per;
long long fac[N];
set<long long> s;
long long n, k, ind, ans;
void bt(long long num) {
if (num > LIM) return;
vec.push_back(num);
bt(num * 10 + 4);
bt(num * 10 + 7);
}
bool f(long long n) {
while (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;
const double dinf = 1e200;
void ext(int c) {}
int ar[30];
bool was[30];
int n;
int k;
long long fact[30];
vector<long long> nums;
void gen(long long v) {
if (v > 1000000000) return;
nums.push_back(v);
gen(v * 10 + 4);
gen(v * 10 + 7);
}
int main() {
fact[0] = 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 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 fact[20], n, k;
bool isGood(long long x) {
while (x) {
if (x % 10 != 4 && x % 10 != 7) return 0;
x /= 10;
}
return 1;
}
vector<long long> getkth(long long k, long long n, long long x) {
vector<long long> v(n + 1, 0);
for (long long i = 1; i <= 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 math
def isLucky(num):
s = str(num)
for i in s:
if i != '4' and i != '7':
return False
return True
def getLucky(d):
if d == 1:
for i in [4, 7]:
yield str(i)
else:
l = [i for i in getLucky(d-1)]
for j in l:
yield '4'+j
for j in l:
yield '7'+j
luckies = []
for d in range(1,11):
for 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 ... | def lucky(x):
return not(set(list(str(x)))-set(['4','7']))
n,k=map(int,raw_input().split())
k-=1
p=[1]*16
for i in xrange(13):p[i+1]=p[i]*(i+1)
a=[]
def n_th(x):
return x if n-x>=13 else (a[x-1-n]+max(0,n-13)+1)
if n<=13 and k>=p[n]:print -1
else:
s=[1]*16
for b in reversed(xrange(min(13,n))):
u=s.index(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>
int lucky(int x) {
while (x) {
if (x % 10 != 4 && x % 10 != 7) break;
x /= 10;
}
if (x == 0) {
return 1;
} else {
return 0;
}
}
int fact(int n) {
int x = 1, i;
for (i = 1; i <= n; i++) x *= i;
return x;
}
int main() {
int n, k, p = 0, q = 2, r = 2, sum = 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 ... | #include <bits/stdc++.h>
using namespace std;
long long N, K;
long long f[15];
int count(long long x, long long k) {
if (x > k) return 0;
return 1 + count(10 * x + 4, k) + count(10 * x + 7, k);
}
bool check(long long x) {
if (x == 0) return false;
while (x) {
long long r = x % 10;
if (r != 4 && r != 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;
template <class T>
string i2s(T x) {
ostringstream o;
o << x;
return o.str();
}
int s2i(string x) {
int r = 0;
istringstream sin(x);
sin >> r;
return r;
}
long long fact[14];
int N, K;
bool isLucky(int x) {
string s = i2s(x);
for (int i = 0; i < s.size(); ... |
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;
double PI = 3.141592653589793;
const int mx = 13;
long long cnt[mx + 1];
int val[mx + 1];
bool lck(int n) {
bool out = 1;
while (n != 0) {
if (n % 10 != 4 && n % 10 != 7) out = 0;
n /= 10;
}
return out;
}
const int bmx = 9;
vector<int> proc;
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 m = 0;
int nn;
long long n, k;
long long fact[20];
long long a[20000];
int b[20];
bool check[20];
int per[20];
bool found;
int res;
void doit(int, int);
void gen(int);
bool isLucky(int);
int main() {
cin >> n >> k;
fact[0] = fact[1] = 1;
for (int i = 2; 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 ... | lucky=set([])
def gen(x):
if x>4444444444:
return
lucky.add(x)
gen(x*10+4)
gen(x*10+7)
gen(4)
gen(7)
lucky=sorted(lucky)
n,k=map(int,raw_input().split())
z=1
t=0
while z<k:
t+=1
z*=t
if t>n:
print -1
raise SystemExit()
def before(x):
l=0
r=len(lucky)-1
while r-l>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 int INF = (int)1E9 + 5;
const long long LINF = (long long)4E18 + 5;
const long double PI = acos(-1.0);
const long double E = 2.718281828459045L;
template <typename T>
T gcd(T a, T b) {
return (b == 0) ? abs(a) : gcd(b, a % b);
}
template <typename T>
inline T lcm(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 ... | import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class CLuckyPermutation {
private static Map<Integer, Integer> map = new HashMap<>();
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan... |
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 + 10, mod = 1e9 + 7;
vector<int> v;
long long fac[N];
int n, k;
bool check(int x) {
while (x) {
int y = x % 10;
x /= 10;
if (y != 4 && y != 7) return 0;
}
return 1;
}
vector<int> get(int cnt, int num) {
set<int> s;
vector<int> 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;
long long lu[] = {
4, 7, 44, 47, 74, 77, 444,
447, 474, 477, 744, 747, 774, 777,
4444, 4447, 4474, 4477, 4744, 4747, 4774,
4777, 7444, 744... |
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 ... | #include <bits/stdc++.h>
using namespace std;
int n, k;
int mx[15];
int cal(int ix) {
if (ix == 0) return 0;
long long temp = 1, i;
for (i = 1;; i++) {
temp *= i;
if (temp >= ix) break;
}
int p = i - 1;
if (temp == ix) {
reverse(mx, mx + p + 1);
return 0;
}
int t = temp / i;
t = (ix - ... |
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):
while x>0:
d=x%10
x/=10
if d!=4 and d!=7:
return False
return True
n,k=map(int,raw_input().split())
k-=1
p=[1]*16
for i in xrange(13):p[i+1]=p[i]*(i+1)
a=[]
def n_th(x):
if n-x<13:
return a[x-1-n]+max(0,n-13)+1
else:
return x
if n<=13 and k>=p[n]:print -1
else:
s=[1]*16... |
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 cf121c {
static TreeSet<Long> lucky = new TreeSet<Long>();
static long[] facts = new long[20];
public static void main(String[] args) {
genLucky(0,12);
facts[0] = facts[1] = 1;
for(int i=2; i<20; i++)
facts[i] = facts[i-1]*i;
Scanner in = new Scanner(System.in);
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;
long long mod = 1000000007;
vector<int> gen_perm(int n, int k) {
long long fact[20];
fact[0] = 1;
for (long long i = 1; i < 20; i++) {
fact[i] = i * fact[i - 1];
fact[i] %= mod;
}
bool placed[20] = {0};
vector<int> v;
for (int p = 1; p <= n; 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>
using namespace std;
const long long dx[] = {4LL, 7LL};
vector<long long> lucky;
vector<long long> P;
int main() {
{
queue<int> Q;
Q.push(0);
while (!Q.empty()) {
long long x = Q.front();
for (int i = 0; i < 2; i++) {
long long x1 = x * 10LL + dx[i];
lu... |
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 sqr(const _T &first) {
return first * first;
}
template <class _T>
inline string tostr(const _T &a) {
ostringstream os("");
os << a;
return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
const long double EPS = 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.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.StringTokenizer;
public class CodeJ
{
static class Scanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringT... |
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 = 100100;
using namespace std;
long long n, k, cnt;
bool used[1000];
void build(long long x, long long mx) {
if (x > mx) return;
if (x) cnt++;
build(x * 10 + 4, mx);
build(x * 10 + 7, mx);
}
bool check(long long x) {
while (x) {
if (x % 10 != 4 && x % 10 != 7) return f... |
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 = 1e18;
long long n, k;
long long tot(long long count) {
if (count > n) return 0;
return 1 + tot(count * 10 + 7) + tot(count * 10 + 4);
}
long long findit(long long a) {
while (a) {
if (a % 10 != 4 && a % 10 != 7) return 0;
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;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lb = 10000000000;
void vrikodara(long long n = 12) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << setprecision(n) << fixed;
}
long long n, k;
set<long long> s;
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;
long long factorial[13], res = 0;
bool OK(int n) {
stringstream ss;
string s;
ss << n;
ss >> s;
ss.clear();
for (int i = 0; i < s.size(); i++) {
if (s[i] != '4' && s[i] != '7') return false;
}
return true;
}
int main() {
int n, k;
cin >> n >> k;
ve... |
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 C {
static int e;
static long count;
public static void construct(int l, String cur) {
if (l == 0) {
if (Integer.parseInt(cur) <= e) {
count++;
}
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 ... | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
public class E {
public static int[] readNNumbers(Buffe... |
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 double pi = acos(-1.0);
const double eps = 1E-7;
const int inf = int(1e9) + 7;
int a[200000];
int tot;
void dfs(long long x, int th) {
if (x > 0) a[tot++] = x;
if (th > 0) {
dfs(x * 10 + 4, th - 1);
dfs(x * 10 + 7, th - 1);
}
}
long long jie(int x) {
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;
long long getLuckyNumberNoGreater(long long mx) {
vector<long long> nums;
if (mx >= 4) nums.push_back(4);
if (mx >= 7) nums.push_back(7);
for (int i = 0; i < nums.size() - 1 + 1; ++i) {
auto x = nums[i];
if (x * 10 + 4 <= mx) nums.push_back(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;
int logfac(long long k) {
long long fac = 1;
int ans = 0;
while (fac < k) {
ans++;
fac *= ans;
}
return ans;
}
int a[100];
long long fact[30];
bool mark[100];
void make_permutation(int now, int n, int k) {
if (now == n) return;
int i;
for (i = 1; i <... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.