text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
long long in, result = std::numeric_limits<long long>::max();
void next(long long n, int fours, int sevens) {
if (fours + sevens <= 10) {
if (n >= in && fours == sevens && n < result) {
result = n;
} else {
next(n * 10 + 4, fours + 1, sevens);
next(n * 10 + 7, fours,... |
#include <bits/stdc++.h>
using namespace std;
const int N = 100024;
char ch[N];
int ans[N], c[N];
int newwpos;
bool found;
bool check(int Nn) {
for (int i = 1; i <= Nn; i++) {
int nownum = ch[i] - '0', nowmost = i <= Nn / 2 ? 7 : 4;
if (nownum == nowmost)
continue;
else if (nownum > nowmost)
r... |
#include <bits/stdc++.h>
using namespace std;
int len;
string s;
int main() {
cin >> s;
len = (int)s.size();
if (len % 2 == 1) {
cout << string(len / 2 + 1, '4') << string(len / 2 + 1, '7') << endl;
return 0;
}
bool lucky = true;
int cnt40 = 0, cnt70 = 0;
for (int i = 0; i < (int)s.size(); i++) {
... |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string n;
cin >> n;
if (((n).size()) % 2) n = '0' + n;
string tmp(((n).size()), '7');
for (int i = (((n).size()) / 2); i < (((n).size())); ++i) tmp[i] = '4';
if (tmp < n) {
for (int i = (0); i < ((((n).size()) / 2 + 1)); ++i) cout << '4';
... |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, c4[100005], c7[100005], co[100005];
char s[1000005];
int main() {
gets(s);
n = strlen(s);
for (i = 0; i < n; i++) {
if (i > 0) {
c4[i] = c4[i - 1];
c7[i] = c7[i - 1];
co[i] = co[i - 1];
}
if (s[i] == '4')
c4[i]++;
e... |
#include <bits/stdc++.h>
using namespace std;
long long int ans = 10e12, n;
void rc(long long int s, int i, int k1, int k2) {
if (k1 == k2 && s >= n) {
ans = min(ans, s);
return;
}
if (i > 10) return;
rc(s * 10 + 4, i + 1, k1 + 1, k2);
rc(s * 10 + 7, i + 1, k1, k2 + 1);
}
int main() {
cin >> n;
rc... |
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
string s, t, ans;
void dfs(int i, int x, int y, bool g) {
if (x > s.size() / 2 || y > s.size() / 2) return;
if (i == s.size()) {
ans = t;
return;
}
if (g) {
t[i] = '4';
dfs(i + 1, x + 1, y, 1);
... |
#include <bits/stdc++.h>
using namespace std;
string s, ans, ans2;
int n;
void dfs(int i, int cnt4, int cnt7, bool big) {
if (cnt4 > n / 2 || cnt7 > n / 2) return;
if (i == n) {
ans2 = ans;
return;
}
if (big) {
ans[i] = '4';
dfs(i + 1, cnt4 + 1, cnt7, 1);
if (ans2 != "") return;
ans[i] =... |
#include <bits/stdc++.h>
using namespace std;
bool issup(long long int a) {
int f = 0, s = 0;
while (a != 0) {
if (a % 10 == 4)
f++;
else
s++;
a /= 10;
}
if (f == s) return true;
return false;
}
int main() {
long long int n;
cin >> n;
queue<long long int> q;
q.push(4);
q.push... |
#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5), mod = int(1e9) + 7;
char second[N];
int n;
int a[N], b[N];
int main() {
scanf("%s", second + 1);
n = strlen(second + 1);
int ok = 1;
for (int i = 1; i <= n; i++) {
if (second[i] != '7') {
if (second[i] > '7') ok = 0;
break;
... |
#include <bits/stdc++.h>
using namespace std;
int n;
string s, t, a;
void dfs(int i, int c4, int c7, bool d) {
if (c4 + n - i < n / 2 || c7 + n - i < n / 2) return;
if (i == n) {
a = t;
return;
}
if (d) {
t[i] = '4';
dfs(i + 1, c4 + 1, c7, 1);
if (a != "") return;
t[i] = '7';
dfs(i +... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count = 0, q = 0;
long long ans = 9999999999999;
cin >> n;
q = n;
while (q) {
q /= 10;
count++;
}
if (count & 1) {
for (int i = 0; i < count / 2 + 1; i++) cout << '4';
for (int i = 0; i < count / 2 + 1; i++) cout << '7';
... |
#include <bits/stdc++.h>
using namespace std;
string ans, s;
long long int ok, l;
void fill(long long int pos, long long int ctr4, long long int ctr7) {
for (long long int i = 0; i < ctr4; i++) ans[pos + i] = '4';
for (long long int i = 0; i < ctr7; i++) ans[pos + i + ctr4] = '7';
ok = 1;
}
void solve(long long i... |
#include <bits/stdc++.h>
char s[100010];
int main() {
int i, j, k, l, m, n, p, q, y, z;
scanf("%s", s);
m = strlen(s);
if (m % 2 == 1) {
for (i = 0; i < (m + 1) / 2; i++) printf("4");
for (i = 0; i < (m + 1) / 2; i++) printf("7");
printf("\n");
return 0;
}
if (s[0] == '1' || s[0] == '2' || s... |
#include <bits/stdc++.h>
using namespace std;
string build(int x, int y) {
string ans;
for (int n_ = (x), i = 0; i < n_; ++i) ans += '4';
for (int n_ = (y), i = 0; i < n_; ++i) ans += '7';
return ans;
}
string solve(string number) {
string ans;
if (((int)(number).size()) % 2 == 1) {
int sz = ((int)(numb... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct num {
long long x;
long long c4;
long long c7;
};
void solve() {
queue<struct num> q;
q.push({0, 0, 0});
vector<long long> v;
while (!q.empty()) {
long long x = q.front().x;
lo... |
#include <bits/stdc++.h>
using namespace std;
int len;
string a, b, c;
int main() {
while (cin >> a) {
b.clear();
c.clear();
len = a.size();
int i;
if (len & 1) {
len++;
for (i = 0; i < len / 2; i++) b += '4';
for (i = len / 2; i < len; i++) b += '7';
} else {
for (i = ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int tt = 1;
for (long long int t = 1; t <= tt; t++) {
string s;
cin >> s;
long long int n = s.size();
if (n % 2 == 0) {
string r = "";
for (long long int i = 1; i <= ... |
#include <bits/stdc++.h>
const int M = 1e5 + 7;
const long long N = 2e9 + 9;
using namespace std;
int n;
queue<pair<long long, int> > q;
int main() {
scanf("%d", &n);
q.push(make_pair(0, 0));
while (1) {
long long x = q.front().first;
int y = q.front().second;
q.push(make_pair(x * 10 + 4, y + 1));
... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const double PI = acos(-1);
const double ERR = 1e-10;
char str[maxn];
char ans[maxn];
int len, n;
int dfs(int pos, int num... |
#include <bits/stdc++.h>
using namespace std;
string getNextLucky(string s) {
int n = s.size();
if (s[0] > '7') {
string ret = "";
for (int i = 0; i <= n; i++) {
ret += '4';
}
return ret;
}
bool flg = false;
for (int i = 0; i < n; i++) {
if (s[i] == '4' || s[i] == '7') continue;
... |
#include <bits/stdc++.h>
using namespace std;
struct _ {
_() { ios_base::sync_with_stdio(0); }
} _;
template <class A, class B>
ostream &operator<<(ostream &o, pair<A, B> t) {
o << "(" << t.first << ", " << t.second << ")";
return o;
}
template <class T>
void PV(T a, T b, int n = 0) {
int c = 0;
while (a < b)... |
#include <bits/stdc++.h>
using namespace std;
const int maxlen = 200000;
char s[maxlen];
int len;
vector<int> v;
vector<int> res;
inline void print(vector<int> &tt) {
for (int i = 0; i < (int)tt.size(); i++) {
cout << tt[i];
}
}
inline bool lss(vector<int> &a, vector<int> &b) {
for (int i = 0; i < (int)a.size... |
#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
using namespace std;
char str[maxn], ans[maxn];
int n, a[maxn];
bool dfs(int pos, int cnt4, int cnt7, bool flag) {
if (pos == n) return true;
if (flag) {
for (int i = 1; i <= cnt4; i++) ans[pos++] = '4';
for (int i = 1; i <= cnt7; i++) ans[pos++] = '7';
... |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int ni() {
int _num;
scanf("%d", &_num);
return _num;
}
int testnum;
void preprocess() {}
string s, t;
bool dfs(int i, int four, int seven, bool slack) {
if (four == 0 && seven == 0) return true;
if (slack) {
t.insert(t.end(), four, '4');
... |
#include <bits/stdc++.h>
using namespace std;
bool superLucky(long long num) {
int fourCtr, sevenCtr;
fourCtr = sevenCtr = 0;
while (num > 0) {
if (num % 10 == 4) {
fourCtr++;
} else {
sevenCtr++;
}
num /= 10;
}
if (fourCtr == sevenCtr) {
return true;
} else
return false;... |
#include <bits/stdc++.h>
using namespace std;
char ch[100000 + 2];
int len;
vector<int> ans;
int cnt[10];
bool flag;
void push(int c, int x) {
while (x--) {
ans.push_back(c);
}
}
bool dfs(int x) {
if (x == len) return false;
if (ch[x] < '4') {
push(4, len - x);
} else if (ch[x] == '4') {
push(4, 1... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e5 + 5, M = 1e3 + 5, OO = 0x3f3f3f3f;
long long n;
set<long long> st;
bool super(long long x) {
int f = 0, s = 0, e = 0;
while (x) {
if (x % 10 == 4)
f++;
else if (x % 10 == 7)
s++;
else
e++;
x ... |
#include <bits/stdc++.h>
int main() {
char s[1000001];
int n, f = -1, i;
int a[100000] = {0};
scanf("%s", s);
n = strlen(s);
if (n % 2 == 1) {
for (i = 0; i < n / 2 + 1; i++) putchar('4');
for (i = 0; i < n / 2 + 1; i++) putchar('7');
puts("");
return 0;
}
for (i = 0; i < n; i++) {
i... |
#include <bits/stdc++.h>
using namespace std;
int n;
char cmd[101000], str[101000];
bool DFS(int pos, int n4, int n7, bool limit) {
if (n4 == 0 && n7 == 0) return 1;
if (limit) {
if (n4) {
str[pos] = '4';
return DFS(pos + 1, n4 - 1, n7, limit);
} else {
str[pos] = '7';
return DFS(pos... |
#include <bits/stdc++.h>
using namespace std;
long long n, n1, n2, mini, mini2;
bool f, f2;
void countfour(long long t1) {
int c4 = 0, c7 = 0;
if (f && mini < t1) return;
string s = to_string(t1);
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '4')
c4++;
else
c7++;
}
if (s.size() % 2 =... |
#include <bits/stdc++.h>
using namespace std;
const double Pi = acos(-1.0);
const int inf = 1000000007;
const long long llinf = 800000000000000119;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int __builtin_popcount(long long x) {
int res = 0;
while (x) {
res += x & 1;
x >>= 1;
}
return res;
... |
#include <bits/stdc++.h>
using namespace std;
string findNthNo(int n) {
string res = "";
while (n >= 1) {
if (n & 1) {
res = res + "4";
n = (n - 1) / 2;
} else {
res = res + "7";
n = (n - 2) / 2;
}
}
reverse(res.begin(), res.end());
return res;
}
bool eq(string n) {
long ... |
#include <bits/stdc++.h>
using namespace std;
string num;
int len;
string big, sma;
bool bigThan(string a, string b) {
if (a.size() > b.size())
return true;
else if (a.size() < b.size())
return false;
else {
for (int i = 0; i < a.size(); ++i)
if (((int)a[i] - (int)b[i]) > 0)
return true;... |
#include <bits/stdc++.h>
using namespace std;
char s[100010];
char s2[100010];
char r[100010];
int n;
inline bool menor(char *s1, char *s2) {
for (int i = 0; s1[i] != '\0'; i++)
if (s1[i] < s2[i])
return true;
else if (s1[i] > s2[i])
return false;
return false;
}
bool vai(int u, int saldo, bool ... |
#include <bits/stdc++.h>
using namespace std;
string crem(int c4, int c7) {
string ans = "";
for (int i = 0, _n = c4; i < _n; i++) ans += "4";
for (int i = 0, _n = c7; i < _n; i++) ans += "7";
return ans;
}
int main() {
string line, ans = "";
int n;
cin >> line;
n = line.length();
if (n % 2) {
n++... |
#include <bits/stdc++.h>
using namespace std;
const int N = 100024;
char ch[N];
int ans[N], c[10], newwpos;
bool found;
bool check(int Nn) {
for (int i = 1; i <= Nn; i++) {
int nownum = ch[i] - '0', nowmost = i <= Nn / 2 ? 7 : 4;
if (nownum == nowmost)
continue;
else if (nownum > nowmost)
retu... |
#include <bits/stdc++.h>
using namespace std;
char str[100005];
int flag[100005];
void print(int len) {
for (int i = 0; i < len / 2; i++) {
printf("4");
}
for (int j = len / 2; j < len; j++) {
printf("7");
}
printf("\n");
}
int main() {
scanf("%s", str);
int len = strlen(str);
memset(flag, 0, si... |
#include <bits/stdc++.h>
using namespace std;
void form(string s) {
int len = s.size();
if (len % 2 == 1) {
len++;
}
for (int i = 0; i < len / 2; i++) printf("4");
for (int j = 0; j < len / 2; j++) printf("7");
printf("\n");
exit(0);
}
string converttolucky(string s) {
int flag = 0;
for (int i = 0... |
#include <bits/stdc++.h>
using namespace std;
int main() {
string in;
cin >> in;
long long inp = stoll(in);
int n = in.size();
string ans;
int cnt;
cnt = n / 2;
if (n % 2 == 1) {
cnt++;
}
while (cnt > 0) {
ans += "4";
cnt--;
}
cnt = ans.size();
while (cnt > 0) {
ans += "7";
... |
#include <bits/stdc++.h>
using namespace std;
string n, s;
long long ok, a, b;
int main() {
cin >> n;
if (n.size() & 1) n = string(n.size() + 1, '4');
for (int i = n.size() - 1; i >= 0; i--) {
if (n[i] < '4') {
a = s.size() + 1;
s.clear();
s = string(a, '4');
b = 0;
ok = 0;
}... |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e6 + 3;
const int inf = (int)1e9;
const int base = 10;
int main() {
string s;
getline(cin, s);
int n = (int)s.size();
if (n % 2 == 1)
cout << string((n + 1) / 2, '4') + string((n + 1) / 2, '7');
else if (string(n / 2, '7') + string(n / 2,... |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
void slucky(long long n, long long f, long long s) {
if (n >= 1e10) return;
if (f == s) v.push_back(n);
slucky(n * 10 + 4, f + 1, s);
slucky(n * 10 + 7, f, s + 1);
}
int main() {
long long a;
cin >> a;
slucky(0, 0, 0);
sort(v.begin(), v.... |
#include <bits/stdc++.h>
#pragma GCC optimize "trapv"
using namespace std;
vector<string> v;
void printAllKLengthRec(char set[], string prefix, long long int n,
long long int k) {
if (k == 0) {
if (count(prefix.begin(), prefix.end(), '4') ==
count(prefix.begin(), prefix.end(), '7')... |
#include <bits/stdc++.h>
using namespace std;
int main() {
static string s, t;
cin >> s;
int n = s.size();
if (!(n & 1))
if (string(n / 2, '7') + string(n / 2, '4') < s)
cout << string(n / 2 + 1, '4') << string(n / 2 + 1, '7') << endl;
else {
int n4 = n / 2, n7 = n / 2;
bool flag = 0;
... |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long mxn = 1e9 + 7;
const long long inf = 1e18;
vector<long long> vec;
void fun(long long n, long long four, long long seven) {
if (n > mxn) {
return;
}
long long tem1 = (10 * n) + 4;
if ((four + 1) == seven) {
vec.p... |
#include <bits/stdc++.h>
using namespace std;
long long ans = 1e11, n;
void lucky(long long a, long long s) {
if (a < ans) {
if (a >= n && s == 0)
ans = a;
else {
lucky(a * 10 + 4, s + 1);
lucky(a * 10 + 7, s - 1);
}
}
}
int main() {
cin >> n;
lucky(0, 0);
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.size() % 2) {
s += "0";
string tmp = "";
for (int i = 0; i < s.size() / 2; i++) tmp += "4";
for (int i = 0; i < s.size() / 2; i++) tmp += "7";
cout << tmp << endl;
return 0;
}
string tmp = "";
for (i... |
#include <bits/stdc++.h>
using namespace std;
void exceed(int j) {
int i;
j = j / 2;
for (i = 0; i < j; i++) cout << 4;
for (i = 0; i < j; i++) cout << 7;
}
int main() {
int sta[20];
int i, j, k, l, four = 0, seven = 0;
;
bool f = true;
char s[20];
scanf("%s", s);
j = strlen(s);
if (j % 2) {
... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T a, T b) {
for (T i = a; i != b; ++i) cout << *i << " ";
cout << endl;
}
template <class T>
void pvp(T a, T b) {
for (T i = a; i != b; ++i)
cout << "(" << i->first << ", " << i->second << ") ";
cout << endl;
}
template <class T>
void ... |
#include <bits/stdc++.h>
using namespace std;
long long ans = 1e18, n;
void lest(long long current, long long counter4, long long counter7) {
if (current >= n) {
if (current < ans && counter4 == counter7) {
ans = current;
return;
}
if (current > n * 100) return;
}
lest(current * 10 + 7, co... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
char temp[100010];
vector<int> ans;
bool dfs(int idx, int cnt4, int cnt7, bool bi, int len) {
if (bi || idx == len) {
for (int i = 0; i < cnt7; ++i) ans.push_back(7);
for (int i = 0; i < cnt4; ++i) ans.push_back(4);
return true;
}
... |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
long long pw(long long b, long long p) {
if (!p) return 1;
long long sq = pw(b, p / 2);
sq *= sq;
if (p % 2) sq *= b;
return sq;
}
vector<long long> vec;
void gen(long long x, int cnt4, int cnt7, int n) {
if (cnt4 == cnt7 && x >= n) vec.... |
#include <bits/stdc++.h>
using namespace std;
vector<long long> all;
void backtrack(long long x, int cnt4, int cnt7) {
if (x > 1e10) return;
if (cnt4 == cnt7) all.push_back(x);
long long nxt = x * 10 + 4;
backtrack(nxt, cnt4 + 1, cnt7);
nxt = x * 10 + 7;
backtrack(nxt, cnt4, cnt7 + 1);
}
int main() {
std:... |
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> res;
void lucky(long long num) {
if (num > 1e10) {
return;
}
int count4 = 0, count7 = 0;
bool isSuper;
string s = to_string(num);
for (unsigned int i = 0; i < s.size(); i++) {
if (s[i] == '4')
count4++;
else
... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int M = 2e5 + 7;
const int inf = 1e9 + 7;
const long long base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;
string s;
int last = 0;
int ans[N];
void solve() {
cin >> s;
if (s.size() % 2 == 1) {
int t = (s.size() + 1) / 2;
... |
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int n;
char f[100005];
bool ans;
void dfs(int idx, int cnt4, int cnt7, int tight, char p[]) {
if (cnt4 > n / 2 || cnt7 > n / 2) return;
if (ans) return;
if (idx == n) {
ans = true;
printf("%s\n", p);
return;
}
if (ans) return;
if (tig... |
#include <bits/stdc++.h>
using namespace std;
vector<long long> vec;
bool che(long long x) {
long long c = 0, d = 0;
while (x > 0) {
if (x % 10 == 7)
c++;
else
d++;
x /= 10;
}
if (c == d)
return 1;
else
return 0;
}
void tec(long long x) {
if (x > 1e10) return;
if (che(x)) v... |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
string s;
while (true) {
s += "47";
sort(s.begin(), s.end());
do {
if (stoll(s) >= n) {
cout << stoll(s);
return 0;
}
} while (next_permutation(s.begin(), s.end()));
}
return 0;
... |
#include <bits/stdc++.h>
using namespace std;
int n;
string s, ret;
bool dfs(int idx, int four, int seven, bool flag) {
if (idx == n) return true;
if (flag) {
for (int i = 0; i < four; i++) ret[idx + i] = '4';
for (int i = four; i < four + seven; i++) ret[idx + i] = '7';
return true;
}
if (four > 0 ... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
string s, res = "";
int check(int i, int j) {
if (n - i < abs(j)) return 0;
if (j >= 0) {
int a = 0, b = j, c = (n - i - j) / 2;
a += c;
b += c;
for (int i = 0; i < b; i++) res += '... |
#include <bits/stdc++.h>
using namespace std;
string s;
bool ch(string t) {
if (t.size() > s.size()) return true;
int i = 0;
while (i < s.size() && s[i] == t[i]) i++;
if (i == s.size() || t[i] > s[i]) return true;
return false;
}
int main() {
string t;
cin >> s;
int n = s.size();
if (n % 2 != 0) n++;
... |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
using namespace std;
char s[101010];
int n, F, S;
int nn, a[101010];
int test() {
for (int i = 0; i < n / 2; i++)
if (s[i] > '7')
return true;
else if (s[i] < '7')
return false;
for (int i = n / 2; i < n; i++)
if (s[i] > '4... |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool eps_dayu(const T &a, const T &b) {
return (a - b) > 1e-10 ? 1 : 0;
}
template <typename T>
inline bool eps_dengyu(const T &a, const T &b) {
if (a - b > 1e-10 || b - a > 1e-10) return 0;
return 1;
}
template <typename T>
inline bool ep... |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const int Maxn = 100005;
using namespace std;
int read() {
int x = 0, f = 1;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = x * 10 + s - '0';
s = getchar();
}
re... |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
if (n <= 1) return false;
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0) return false;
return true;
}
long long factorial(long long n) {
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}
bool primeFactors(int n, ... |
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int sum[100005], a[100005], b[100005];
int big, n, seven, four, i;
void Print(int n) {
if (n & 1) ++n;
for (int i = 1; i <= n / 2; i++) putchar('4');
for (int i = 1; i <= n / 2; i++) putchar('7');
exit(0);
}
void Write() {
for (int i = 1; i <= n; i... |
#include <bits/stdc++.h>
using namespace std;
char s[100555];
int main() {
int n, i, j, b4, b7;
gets(s);
n = strlen(s);
if (n % 2 == 1) {
for (i = 0; i < (n + 1) / 2; i++) printf("4");
for (i = 0; i < (n + 1) / 2; i++) printf("7");
return 0;
}
i = 0;
b4 = 0;
b7 = 0;
while (i < n && (s[i] =... |
#include <bits/stdc++.h>
using namespace std;
long long next(long long n) {
if (n % 10 < 4)
return n / 10 * 10 + 4;
else if (n % 10 < 7)
return n / 10 * 10 + 7;
else
return next(n / 10) * 10 + 4;
}
bool good(long long n, int a, int b) {
if (n == 0) return (a == b);
if (n % 10 == 4)
a++;
else... |
#include <bits/stdc++.h>
using namespace std;
void init() {
cin.tie(0);
cin.sync_with_stdio(0);
}
long long n, lst = 1e10;
void lucky(long long a, int s, int f) {
if (a > 1e10) return;
if (a >= n && s == f) lst = min(lst, a);
lucky(a * 10 + 4, s, f + 1);
lucky(a * 10 + 7, s + 1, f);
}
void luk(int s, int f,... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T modinv(T a, T n) {
T i = n, v = 0, d = 1;
while (a > 0) {
T t = i / a, x = a;
a = i % x;
i = x;
x = d;
d = v - t * x;
v = x;
}
return (v + n) % n;
}
long long modpow(long long n, long long k, long long mod) {
lon... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
char a[MAXN], ans[MAXN];
int n;
int main() {
cin >> (a + 1);
int n = strlen(a + 1);
if (n & 1) {
ODD_N:
for (int i = 1; i <= n / 2 + 1; i++) {
putchar('4');
}
for (int i = 1; i <= n / 2 + 1; i++) {
putchar('7');
... |
#include <bits/stdc++.h>
using namespace std;
long long digits(long long n) {
long long count = 0;
while (n > 0) {
count++;
n /= 10;
}
return count;
}
int main() {
long long n;
cin >> n;
long long nd = 0;
string r;
string s;
nd = digits(n);
if (nd % 2 == 1) {
for (long long i = 0; i < ... |
#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
int i, k, sev_q, four_q, last_four_idx, four_c = 0, sev_c = 0, last_idx;
char *in = (char *)calloc(100000 + 1 + 2, 1);
scanf("%s", in + 1);
sev_q = in[1] == '7';
four_q = in[1] == '4';
if (four_q) {
last_four_idx = 1;
four_c++;
} else if ... |
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> v;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string s = "47";
long long t = 2;
while (t--) {
next_permutation(s.begin(), s.end());
stringstream geek(s);
long long x = 0;
geek >> x;
v... |
#include <bits/stdc++.h>
using namespace std;
int a[100002], c[100002];
int main() {
int i, j, k1 = 0, k2 = 0, n;
a[0] = 0;
string s;
cin >> s;
n = s.length();
if (n % 2 == 1) {
for (i = 1; i <= (n + 1) / 2; i++) cout << 4;
for (i = 1; i <= (n + 1) / 2; i++) cout << 7;
} else {
for (i = 1; i <... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
int n = 11;
long long res = 1e15;
for (int mask = 0; mask < (1 << n); mask++) {
long long num = 0;
int cnt4 = 0, cnt7 = 0;
for (int i = n - 1; i >= 0; i--) {
if (mask & (1 << i)) {
num = num * 10 + 7;
... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
string s;
cin >> s;
int n = s.size();
if (n % 2 == 1) {
for (int i = 0; i < n + 1; ++i) {
cout << (i < (n + 1) / 2 ? 4 : 7);
}
cout << endl;
return 0;
}
int seven = 0, four = 0;
for (int i = 0; i < n; ++... |
#include <bits/stdc++.h>
using namespace std;
string s, ans;
int n;
bool solve(int p, int n4, int n7, bool ok) {
if (p == n) return 1;
if (ok) {
for (int i = 0; i < n7; ++i) ans += '7';
for (int i = 0; i < n4; ++i) ans += '4';
return 1;
}
if (n4 >= 1 && s[p] <= '4' && solve(p + 1, n4 - 1, n7, s[p] <... |
#include <bits/stdc++.h>
using namespace std;
const int MAX_K = 100000;
char s[MAX_K + 4];
int ds[MAX_K + 4];
int fillds(int ds[], int p, int n4, int n7) {
while (n4--) ds[p++] = 4;
while (n7--) ds[p++] = 7;
return p;
}
int rollback(int ds[], int p, int h, int n4, int n7) {
p--;
while (p >= 0) {
if (ds[p]... |
#include <bits/stdc++.h>
char s[100010];
char pp[100010];
bool dfs(int pos, int n4, int n7, bool doing) {
if (n4 + n7 == 0) return true;
if (!doing) {
if (n4) {
pp[pos] = '4';
return dfs(pos + 1, n4 - 1, n7, doing);
} else {
pp[pos] = '7';
return dfs(pos + 1, n4, n7 - 1, doing);
... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
cin >> s;
if (s.size() % 2 == 1) {
int p = s.size() + 1;
for (int j = ... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string t;
cin >> t;
int n = t.length();
if (n & 1) {
for (int i = 0; i < (int)(n + 1) / 2; ++i) {
cout << 4;
}
for (int i = 0; i < (int)(n + 1)... |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
string s;
void answer(string ans) {
if (ans < s || ans.size() % 2) {
int n = ((s.size()) / 2) + 1;
ans = string(n, '4') + string(n, '7');
}
cout << ans << '\n';
exit(0);
}
int main() {
cin >> s;
int n = s.size();
s[n - 1]--;
... |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline long long lin() {
long long x;
scanf("%lld", &x);
return x;
}
char ch[4000010];
inline string get() {
scanf("%s", ch);
return string(ch);
}
inline void read(int *a, int n) {
for (int i = 0; i... |
#include <bits/stdc++.h>
using namespace std;
inline int random(int max) {
return int(double(rand()) * max / (RAND_MAX + 1.0));
}
struct edge {
int src, dst, next;
int w;
edge(int src = 0, int dst = 0, int w = 0, int next = -1)
: src(src), dst(dst), w(w), next(next) {}
};
bool operator<(const edge& e, con... |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000 * 1000 + 100;
int n;
string s;
char res[maxN];
bool solve(int x, int four, int seven) {
if (x == n) return 1;
if (s[x] > '7') return 0;
if (s[x] == '7')
if (seven == 0)
return 0;
else {
res[x] = '7';
return solve(x + 1, ... |
#include <bits/stdc++.h>
using namespace std;
char n[100010];
char a[100010];
int main() {
scanf("%s", n);
int l = strlen(n);
if (l % 2 == 1) {
for (int i = 0; i < (l + 1) / 2; i++) putchar('4');
for (int i = 0; i < (l + 1) / 2; i++) putchar('7');
printf("\n");
return 0;
} else {
int m4 = l ... |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long mini = 1e12;
void solve(long long lucky = 0, int c = 0) {
if (lucky > 1e11) return;
if (lucky >= n && c == 0) mini = min(mini, lucky);
solve(lucky * 10 + 4, c + 1);
solve(lucky * 10 + 7, c - 1);
}
int main() {
cin >> n;
solve();
cout << ... |
#include <bits/stdc++.h>
using namespace std;
int n = 3000;
bool arr[3002];
int ar[3002];
void prime() {
for (int i = 2; i < n; i += 2) {
arr[i] = 1;
}
arr[2] = 0;
for (int j = 3; j * j < n; j++) {
if (!arr[j])
for (int i = j * j; i < n; i += j) arr[i] = 1;
}
}
void getall(int x) {
ar[6] = 1;
... |
#include <bits/stdc++.h>
using namespace std;
queue<pair<long long, long long> > v;
int main() {
long long x, val, c;
cin >> x;
v.push(make_pair(0, 0));
while (!v.empty()) {
val = v.front().first;
c = v.front().second;
v.pop();
if (val >= x && c == 0) return cout << val, 0;
v.push(make_pair(... |
#include <bits/stdc++.h>
using namespace std;
int d2x[] = {1, -1, 0, 0, 1, -1, 1, -1};
int d2y[] = {0, 0, 1, -1, 1, -1, -1, 1};
int d3x[] = {1, -1, 0, 0, 0, 0};
int d3y[] = {0, 0, 1, -1, 0, 0};
int d3z[] = {0, 0, 0, 0, 1, -1};
struct edge {
int from, to, w;
edge(int from, int to, int w) : from(from), to(to), w(w) {... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 2e5 + 10;
void refrain(string &str) {
if (str.length() % 2 == 1) {
int o = (str.length() + 1) / 2;
str = string(o, '4') + string(o, '7');
return;
}
int l = str.length();
for (int i = 0; i < l; i++) {
if (s... |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
char x[N];
int main() {
scanf("%s", x + 1);
x[0] = '0';
int k = strlen(x + 1);
if (k % 2 == 1) {
k = k / 2 + 1;
for (int i = 0; i < k; i++) printf("4");
for (int i = 0; i < k; i++) printf("7");
puts("");
return 0;
}
for ... |
#include <bits/stdc++.h>
using namespace std;
char s[100100];
char s1[100100];
int num[100100];
char res[100100];
void out(int n) {
for (int i = (0); i < (n); ++i)
if (i < n / 2)
printf("4");
else
printf("7");
printf("\n");
}
int n;
bool r(int p, int cnt1, int cnt2, bool f) {
if (p == n) {
... |
#include <bits/stdc++.h>
int n, m, i, j, a, b;
char s[100100], t[100100];
bool q;
void go(int m) {
for (i = 0; i < m; i++) putchar('4');
for (i = 0; i < m; i++) putchar('7');
}
int main() {
gets(s);
n = strlen(s);
if (n & 1) {
go((n + 1) / 2);
return 0;
}
a = b = n / 2;
for (i = 0; i < n; i++) {... |
#include <bits/stdc++.h>
using namespace std;
int mod = 1e8 + 7;
int main() {
char c[100005];
while (scanf("%s", c + 1) != EOF) {
char ans[100005];
memset(ans, 0, sizeof(ans));
for (int i = 1; c[i] != 0; i++) {
if (c[i] > '7') {
for (int j = i - 1; j >= 0; j--) {
if (ans[j] == '4... |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
int main() {
string str, ans;
int n, idx, a, b;
cin >> str, n = str.size();
if (n % 2 || str > (string(n >> 1, '7') + string(n >> 1, '4')))
cout << string(n / 2 + 1, '4') + string(n / 2 +... |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<long long> ans;
string str = "47";
ios::sync_with_stdio(0);
cin.tie(0);
while (str.size() <= 8) {
do {
ans.push_back(stoi(str));
} while (next_permutation(str.begin(), str.end()));
str += "47";
s... |
#include <bits/stdc++.h>
using namespace std;
void pt(long long int n) {
long long int d = n / 2;
long long int t = 4;
for (int i = 1; i <= n; ++i) {
cout << t;
if (i == d) t = 7;
}
}
int main() {
string s;
cin >> s;
if (s.length() % 2 == 1) {
pt(s.length() + 1);
return 0;
}
long long ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.