Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int N1 = 1e7 + 100; const int N2 = 1e6 + 100; const int N3 = 1e5 + 100; int p[N1], pri[N2], pn; void init() { int n = 1e7; memset(p, 0, sizeof(p)); pn = 0; for (int i = 2; i <= n; i++) { if (!p[i]) { pri[pn++] = i; } for (int j = 0; j < pn; j...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int INF = 1000 * 1000 * 1000; const double EPS = 1e-9; const int MAX_VAL = 10000000 + 1; const int MAXN = 100000 + 1; bool isPrime[MAX_VAL]; int primes[MAX_VAL]; int a[MAXN]; int b[MAXN]; int cnta[MAX_VAL]; int cntb[MAX_VAL]...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; inline long long labs(long long a) { return a < 0 ? (-a) : a; } template <typename T> inline T sqr(T x) { return x * x; } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } vector...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.util.*; import java.io.*; public class Main{ BufferedReader in; StringTokenizer str = null; private String next() throws Exception{ if(str == null || !str.hasMoreElements()) str = new StringTokenizer(in.readLine()); return str.nextToken(); } private int nextInt() throws Exception...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 10000005; int prime[MAXN]; void Prime() { int i, j; for (i = 0; i < MAXN; i++) prime[i] = 1; prime[0] = prime[1] = 0; for (i = 2; i < MAXN; i++) { if (!prime[i]) continue; for (j = i * 2; j < MAXN; j += i) prime[j] = 0; } } int a[10000005]...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); template <class T> T SQR(const T &a) { return a * a; } const int SZ = 1e7 + 1; int pr[1000000]; int st[SZ] = {0}; int prCnt = 0; int del[SZ] = {0}; void run() { for (int i = (2), ei = (SZ); i < ei; i++) { if (del[i] == 0) { del[i]...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int PN = 1000000, PP = 10000100; int n, m; vector<int> p, A[PN], B[PN]; bool notp[PP]; int main() { for (int i = 2; i < PP; i++) if (!notp[i]) { p.push_back(i); for (long long j = i * 1LL * i; j < PP; j += i) notp[j] = true; } ios_base::sync_wi...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> A, B; int d[10000010]; int a[10000010]; int pr[10010], pn; bool isp[100010]; void GetPrime(int n) { memset(isp + 2, 1, sizeof(isp) - 2); for (int i = 2; i < n; i++) { if (isp[i]) pr[pn++] = i; for (int j = 0; j < pn && pr[j] * i < n; j++) {...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 10; const int M = 1e5 + 10; int n, m; int p[N], up[N], down[N]; int a[M], b[M]; void init() { for (int i = 2; i < N - 9; i++) { if (p[i]) continue; p[i] = i; for (int j = i + i; j < N - 9; j += i) p[j] = i; } } int main() { ios::sync_wi...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.FileNotFoundException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.HashMap; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.File; import java.io.Writer; import java.util.Collection; import java.util.List; import...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int Max1 = 1e7 + 9, Max2 = 1e5 + 9; int a[Max1], b[Max1], M[Max1], na[Max1], nb[Max1], g[Max2], h[Max2]; int main() { for (long long i = 2; i < Max1; i++) if (!M[i]) { M[i] = i; for (long long j = i * i; j < Max1; j += i) M[j] = i; } int n, m, ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; public class C6 { static boolean DBG = true; static int N = 100010, S = 10000010, n, m; static ...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; // https://codeforces.com/problemset/problem/222/C public class Problem137C { public static void main(String[] args) throws Exception { int[] spf = smallestPrimeFactor(10000000); BufferedReader reade...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e7 + 10; const int maxx = 1e5 + 10; int prime[maxn], num[maxn], a[maxx], b[maxx]; bool vis[maxn]; int cnt = 0; void init() { for (int i = 2; i < maxn; i++) { if (!vis[i]) prime[cnt++] = i; for (int j = 0; j < cnt && i * prime[j] < maxn; j++) { ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchException; import java.util.Linke...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; char primes[10000005] = {}; int useda[10000005] = {}; int usedb[10000005] = {}; int cut[10000005] = {}; vector<int> g; void init() { memset(primes, 1, sizeof(primes)); primes[0] = primes[1] = 0; for (int i = 2; i < 10000005; i++) { if (primes[i] == 0) continue; ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int prime[10000005] = {0}; int a[100005], b[100005]; int ap[10000005], bp[10000005]; void check(int *x, int *y, int len) { for (int i = 0; i < len; ++i) for (int j = x[i]; j > 1; j /= prime[j]) y[prime[j]]++; } void print(int *x, int *y, int len) { int cnt; for (i...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 10000010; int prime[maxn / 10], num, mi[maxn]; bool flag[maxn]; int cnt[maxn][2]; int a[100010], b[100010]; vector<int> afac[100010]; vector<int> bfac[100010]; int main() { for (int i = 2; i < maxn; i++) { if (!flag[i]) prime[++num] = i, mi[i] = i; ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.*; import java.util.*; import java.math.*; public class Main { static StringTokenizer st; static PrintWriter out = new PrintWriter(System.out,true); static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public static int nextInt() throws Exception { if...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int n, m; bool p[10000006]; int smpf[10000006]; int u[10000007], d[10000007]; int num[100005], den[100005]; int main() { scanf("%d", &n); scanf("%d", &m); for (int i = 1; i <= n; i++) scanf("%d", &num[i]); for (int i = 1; i <= m; i++) scanf("%d", &den[i]); memset(...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 10000000; const int PN = 664579; int N; int minp[MAXN + 1], p[PN]; int initPrime(int n = MAXN) { int N = 0; memset(minp, -1, sizeof(minp)); for (int i = 2; i <= n; ++i) { if (minp[i] == -1) p[N] = i, minp[i] = N++; for (int j = 0; j < N && i *...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.*; import java.util.*; public class P222C { public static StringTokenizer st; public static void nextLine(BufferedReader br) throws IOException { st = new StringTokenizer(br.readLine()); } public static String next() { return st.nextToken(); } pu...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; int times[10000015]; int dtimes[10000015]; int Tnums[100012]; int Bnums[100012]; vector<int> primes; void get_inp(int Knums[], int r, int timel[]...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.math.*; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { PrintWriter out = new PrintWriter(System.out); FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in))); Task solver = n...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; bool sieve[10000001]; int fprime[10000001]; vector<pair<int, int> > ppf; void primeTable() { int i, j; int lim = sqrt((double)10000001) + 6; memset(fprime, -1, sizeof(fprime)); fprime[2] = 2; for (i = 4; i < 10000001; i += 2) sieve[i] = true, fprime[i] = 2; for ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf("%d", &x); return x; } inline string get() { char ch[10000]; scanf(" %s", ch); return ch; } template <class P, class Q> inline P smin(P &a, Q b) { if (b < a) a = b; return a; } template <class P, class Q> inline P smax(P &a...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.*; import java.util.*; import java.math.*; public class Solution { public static void main(String[] args) throws IOException { new Solution().run(); } StreamTokenizer in; Scanner ins; PrintWriter out; int nextInt() throws IOException { in.nextToken(); ...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 1e7 + 7; map<int, vector<int> > mp; int a[N], b[N]; int spf[M]; void sieve() { spf[1] = 1; for (int i = 2; i < M; i++) spf[i] = i; for (int i = 4; i < M; i += 2) spf[i] = 2; for (int i = 3; i <= sqrt(M); i++) { if (spf[i] == i) { ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.FileNotFoundException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.HashMap; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.File; import java.io.Writer; import java.util.Collection; import java.util.List; import...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse4") using namespace std; long long c[10000005]; long long p[10000005]; vector<long long> a, b; vector<long long> pr; void prime() { p[0] = 0; p[1] = 0; long long i, j; for (i = 2; i < 10000005; i++...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; void reop_func(const char *in) { freopen(in, "r", stdin); } const int MAXN = 10000001; int a[2][100001], lim[2], d[MAXN], cnt[2][MAXN]; int main() { ("in.txt"); int pr_cnt = 0; scanf("%d %d", &lim[0], &lim[1]); for (int i = 0; i < 2; i++) for (int j = 0; j < lim...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.util.*; import java.io.*; import java.lang.*; import java.math.BigInteger; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inpu...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; void read_file(bool outToFile = true) {} int n, m; int A[100000 + 9], B[100000 + 9]; int cntA[664579 + 1 + 9], cntB[664579 + 1 + 9]; bitset<10000000 + 1 + 9> isPrime; vector<int> prime; int pdiv[10000000 + 1 + 9]; void sieve() { isPrime.set(); isPrime[0] = isPrime[1] = ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:300000000") #pragma warning(disable : 4800) using namespace std; void showTime() { cerr << (double)clock() / CLOCKS_PER_SEC << endl; } const double pi = 3.1415926535897932384626433832795; template <class T> T abs(const T &a) { return a >= 0 ? a : -a; }; templat...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int inf = 2147483647; const long long ll = 9223372036854775807, ninf = 1000000000; const double eps = 1e-6; const long long nll = 223372036854775807; int prime[10000005] = {}; int cnt1[10000005] = {}; int cnt2[10000005] = {}; int A[100005] = {}; int B[100005] = {}; int main...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int pw(int a, int b) { int ans = 1; for (int i = 1; i <= b; ++i) ans *= a; return ans; } const int N = 100010; map<int, int> ma, mb, m1, m2; vector<pair<int, int> > a[N], b[N]; int pLst[4010], pCnt; int main() { int i, j, k; int n, m; for (i = 2; i <= 4000; ++i)...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; bool deb_mode = 0; class debugger { vector<string> vars; public: template <typename T> debugger &operator,(const T v) { stringstream ss; ss << v, vars.push_back(ss.str()); return *this; } void printall() { int j = 0, l = vars.size(); for (int...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Cf137C { int primes[] = new int[(int)1e6 + 1]; int nP...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.PrintWriter; import java.util.Scanner; public class CC { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int[] pr = new int[10000001]; int[] aa = new int[10000001]; ...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
// Don't place your source in a package import javax.swing.*; import java.lang.reflect.Array; import java.text.DecimalFormat; import java.util.*; import java.lang.*; import java.io.*; import java.math.*; import java.util.stream.Stream; // Please name your class Main public class Main { static FastScanner fs=new ...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> const double pi = acos(-1.0), eps = 1e-9; const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1}; const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1}; const int MO = (int)(1e9 + 7); using namespace std; int a[1000001], b[1000001], n, m; int now1[1000001], now2[1000001], num1[1000001], num2[1000001]; bool f[10...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.util.*; import java.io.*; public class CodeForces { static int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; static int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; static final int INF = (int) 1e9 + 10; public static void main(String[] args) throws IOException { in.init(System.in); for (in...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int sz = 33 * 1e5; const int MInt = 1e7 + 5; void get_pf(int n, int *pf) { for (int i = 0; i <= n; i++) pf[i] = i; for (int i = 4; i <= n; i += 2) pf[i] = 2; for (int i = 3; i * i <= n; i += 2) { if (pf[i] != i) continue; for (int j = i * i; j <= n; j +=...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.Locale; import java.io.OutputStream; import java.util.RandomAccess; import java.io.PrintWriter; import java.util.AbstractList; import java.io.Writer; import java.util.List; import java.io.IOException; import java.math.BigDecimal; import ...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int maxS = 10000 + 10; const int maxA = 10000000 + 10; const int maxN = 100000 + 10; int a[maxN], b[maxN]; map<int, int> acnt, bcnt; vector<int> prime; vector<bool> mark; void sieve(void) { mark.resize(maxS, true); mark[0] = mark[1] = false; for (int i = 2; i < ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; const long long SIZE = 1e5 * 2 + 10, S2 = 1e6 * 2, MOD = 1e9 + 7, INF = 1e9 * 1e2, P = 28, MOD2 = 1e9 + 3, P2 = 27; const int N = 1e7 + 10; int lp[N + 1]; vector<int> pr; struct op { string var; long long type; string a, b; }...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
# Legends Always Come Up with Solution # Author: Manvir Singh import os from io import BytesIO, IOBase import sys from collections import Counter from math import sqrt, pi, ceil, log, inf, gcd, floor def main(): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input()...
PYTHON3
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.fill; import static java.lang.Math.*; import static java.util.Arrays.sort; import static java.util.Collections.sort; public class C222 { public static int mod = 1000000007; public static long INF = (1L << 60); static FastS...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const int N = 1e7; const long long mod = 1e9 + 7; const int bits = 20; const long double pi = 3.14159265358979323846; int firstf[N + 1], isprime[N + 1]; vector<int> primes; map<int, int> indx; void pre() { firstf[1] = 1; for (int i = 2; i <= ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int fact[2][10000007], prim[10000007]; int a[100005], b[100005]; bool flag[10000007]; int lab[10000007]; int pcnt; void pre() { int i = 2; pcnt = 0; while (i <= 10000000) { if (!flag[i]) { lab[i] = i; prim[pcnt++] = i; } for (int j = 0; j < pcn...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class ReducingFractions { public static void main(String[] args) { //Use Exhaustion boolean debug = false; FastReader sc = new FastReader(); int...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> int intcmp(const void *f, const void *s) { return (*(int *)f - *(int *)s); } int gcd(int a, int b) { return ((b == 0) ? a : gcd(b, a % b)); } int a[11234567]; int b[11234567]; int largestprimediv[11234567]; int hist[11234567]; void use(int n, int add) { while (largestprimediv[n]) { hist[l...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 9; long long int fact[300010]; const long long int N = 100005; const long long int MAX = 10000010; long long int power(long long int x, long long int n) { long long int res = 1; while (n > 0) { if (n % 2 == 1) res = (res * x) % mod; ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int p[10000005]; void predo() { for (int i = 2; i * i < 10000005; i++) if (!p[i]) for (int j = i * i; j < 10000005; j += i) p[j] = i; for (int i = 2; i < 10000005; i++) if (!p[i]) p[i] = i; } void shik(int n, int s[], int t[]) { for (int i = 0; i < n; i+...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e7 + 10; int dv[maxn], a[maxn], b[maxn]; vector<int> ca, cb, lim; bool v[maxn]; vector<int> pr; void sieve() { for (int i = 2; i < maxn; ++i) { if (!v[i]) v[i] = true, dv[i] = pr.size(), pr.push_back(i); for (int j = 0; i * pr[j] < maxn; ++j) { ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const double PI = 2 * acos(0.0); const double eps = 1e-9; const long long PRIMESZ = 10000010; bool isprimes[PRIMESZ]; int nfactors[PRIMESZ], mfactors[PRIMESZ], nremoved[PRIMESZ], mremoved[PRIMESZ]; long long n, m, arrn[100010], arrm[100010], tarrn[1...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.util.ArrayList; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top */ public ...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.*; import java.util.*; public class CodeForces extends Functions { private static void solve() { int max = (int)1e7+1; int n = sc.nextInt(); int d = sc.nextInt(); int[] numerator = sc.setintArray(n); int[] denominator = sc.setintArray(d); int[] prime...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; vector<int> primo; unordered_map<int, int> pos; const int LIM = 1e7; bool prime[LIM] = {}; void fill() { primo.push_back(2); pos[2] = 0; for (int i = 3; i < LIM; i += 2) { if (prime[i] == 0) { pos[i] = primo.size(); primo.push_back(i); if (i <= L...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.math.BigInteger; import java.util.InputMismatchException; /** * Actual s...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.Arrays; public class C222 { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWri...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = int(1.5 * 1e7); const int inf = 1e9 + 7; const long long ll_inf = 1e18 + 420; const double eps = 1e-4; const int N = 1e6 + 7; const int MAX = 2e5 + 9; const int mod = 1e9 + 7; const long double pi = 3.14159265359; long long prime[10000010], n, m, a[100010],...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const long long ms = 1e7 + 1, mx = 1e5 + 5; int n, m; vector<int> prime; bool notPrime[ms]; int num[ms], dem[ms]; int arr[mx], brr[mx]; vector<int> fact(int x) { vector<int> ans; return ans; } int main() { prime.push_back(2); for (int i = 4; i < ms; i += 2) { no...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int n, m; int arr[200100]; map<int, vector<int> > inds; vector<int> ps; int isp[5000]; int main() { for (int i = (2), _i = (5000); i < _i; ++i) { if (!isp[i]) { ps.push_back(i); for (int j = i + i; j < 5000; j += i) isp[j] = true; } } cout << fixed...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const int maxn = 10000001; bool p[maxn] = {0}; int prime[674590], pos[maxn]; int a[100005], b[100005]; int len; void pre_deal() { len = 0; for (int i = 2; i < maxn; i++) { if (!p[i]) { prime[len] = i; pos[i] = len++; for...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int num[10001000], den[10001000]; long long arra[100100], arrb[100100]; int n, m; bool isprime[10001000]; void init() { memset(isprime, 0, sizeof(isprime)); for (int i = 2; i <= 10000000; i++) { if (!isprime[i]) { for (int j = i * 2; j <= 10000000; j += i) isp...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int MAX_SQRT = sqrt(10000000) + 1; vector<int> primes; for (int i = 2; i < MAX_SQRT; i++) { int j = 2; for (; j * j <= i; j++) if (i % j == 0) break; if (j * j > i) primes.push_back(i); } int n, m, a1[100001], b1[100001]; vector<pa...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; import static java.lang.Double.parseDouble; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.Math.max; import static...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 10 * 1000 * 1000 + 10; const int M = 100 * 1000 + 20; int n, m, a, cntp[N], cnt[N], cnt_[N], p[N], x[M], y[M]; bool mark[N]; int main() { for (int i = 2; i <= N; ++i) { if (mark[i]) continue; p[i] = i; for (int j = 2; j * i <= N; ++j) { mar...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, ai, bi; cin >> n >> m; vector<int> divs(10000001, 0); for (int j = 2; j < 10000; j++) { if (!divs[j]) { int k = j; while (k * j < 10000001) { if (!divs[k * j]) divs[k * j] =...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int p[5000]; bool prime[5000]; int a[100005]; int b[100005]; int up; map<int, int> fm; map<int, int> fz; void Prime() { int i, j; memset(prime, 0, sizeof(prime)); for (i = 2; i <= 3500; i++) { if (prime[i] == 1) continue; p[up++] = i; for (j = i * i; j <= ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int divs[10000007], num[10000007], den[10000007], prms[2][10000007], minipow[10000007]; void sieve() { divs[0] = divs[1] = 2; for (int i = 2; i < 1e7 + 1; i++) { if (!divs[i]) for (int j = i; j < 1e7 + 1; j += i) { divs[j] = i; } } } int ma...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int n; int PRIMES_COUNTER = 0; int up[10000001]; int down[10000001]; vector<int> up_result; vector<int> down_result; int nums[10000001]; int ups[100009]; int downs[100009]; int main() { for (int i = 2; i < 10000001; ++i) { if (nums[i]) continue; for (int j = i + i...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; map<int, int> up; map<int, int> down; map<int, int> cnt; map<int, int> now; int a[100005]; int b[100005]; int n, m; int prime[20010]; bool flag[20010]; int tot; void findPrime() { tot = 0; for (int i = 2; i < 20000; i++) if (!flag[i]) { prime[++tot] = i; ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.util.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class C { final int SIZE = 10001000; //final int SIZE = 10000; int[] factor = new int [SIZE+1]; // ���O�̑f���� int[] cntbo = new int [SIZE+1]; // ����̑f���̕p�x int[] cntshi = new int [SIZE+1]; // ���q�̑f...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e7; int diva[MAXN]; int divb[MAXN]; int cnt[MAXN]; int fdiv[MAXN + 10]; void re() { for (int i = 2; i <= MAXN; i += 2) fdiv[i] = 2; for (int i = 3; i <= MAXN; i += 2) { if (fdiv[i] == 0) { for (int j = i; j <= MAXN; j += i) if (fdiv[j...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; ...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e7 + 1; char used[MAXN] = {0}; int lowest_divisor[MAXN]; int numbers[2][MAXN], numbers2[2][MAXN]; void sieve() { for (int i = 2; i < MAXN; i += 2) { used[i] = 1; lowest_divisor[i] = 2; } for (long long i = 3; i < MAXN; i += 2) { if ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; long n, m, a[100020], b[100020]; long fact_num[10000020]; long fact_den[10000020]; long p[10000020]; void factorization(long n, long a[], long fact[]) { for (long i = 0; i < n; ++i) { for (long j = a[i]; j > 1; j /= p[j]) fact[p[j]]++; } } void reduction(long n, lon...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; ...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
// practice with kaiboy import java.io.*; import java.util.*; public class CF222C extends PrintWriter { CF222C() { super(System.out, true); } static class Scanner { Scanner(InputStream in) { this.in = in; } InputStream in; byte[] bb = new byte[1 << 15]; int i, n; byte getc() { if (i == n) { i = n = 0; ...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; int flag[10000010] = {0}; void init() { for (int i = 4; i <= 10000010; i += 2) flag[i] = 2; for (int i = 3; i <= 10000010 / i; i += 2) { if (flag[i] == 0) { for (int j = i * i; j < 10000010; j += i * 2) flag[j] = i; } } } void func(vector<int>& ans, vect...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; template <typename T> inline void Int(T &n) { n = 0; int f = 1; register int ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0'; n = n * f; } template <typename T...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; vector<int> prime; bool canbe[10000007]; void precalc() { for (int i = 2; i <= 10000000; ++i) { if (!canbe[i]) { prime.push_back(i); for (int j = 2; j * i <= 10000000; ++j) canbe[j * i] = true; } } } class DSU { pri...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int PN = 1000000, PP = 10000100; int n, m; vector<int> p, A[PN], B[PN]; bool notp[PP]; int main() { for (int i = 2; i < PP; i++) if (!notp[i]) { p.push_back(i); for (long long j = i * 1LL * i; j < PP; j += i) notp[j] = true; } cin >> n >> m; ...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pradyumn Agrawal coderbond0...
JAVA
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
#include <bits/stdc++.h> using namespace std; const int lim = 10000005; const int N = 100005; int a[N], b[N], f[lim], g1[lim], g2[lim], g3[lim]; int main() { int n, m; cin >> n >> m; for (int i = 2; i <= lim; i++) if (f[i] == 0) { f[i] = i; for (int j = i + i; j <= lim; j += i) f[j] = i; } f...
CPP
222_C. Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
2
9
import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.Locale; import java.io.OutputStream; import java.util.RandomAccess; import java.io.PrintWriter; import java.util.AbstractList; import java.io.Writer; import java.util.List; import java.io.IOException; import java.math.BigDecimal; import ...
JAVA
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
n=int(raw_input()) if n==1 or n==2: print -1 else: a=[] for i in range(2,n+1): a.append(i) a.append(1) for i in a: print i,
PYTHON
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
import java.util.*; public class index { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int input = cin.nextInt(); if (input == 1 || input == 2) { System.out.println(-1); return; } for(int i = input...
JAVA
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
def s(a): k = len(a) for i in range(k-1): for j in range(i,k-1): if a[j] > a[j+1]: a[j],a[j+1] = a[j+1],a[j] return a def main(): n = int(input()) if n <= 2: v = [-1] else: v = [int(i) for i in range(n,0,-1)] print(*v,sep = ' ') if __name__...
PYTHON3
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf(" %d", &n); if (n == 1 || n == 2) printf("-1\n"); else { printf("%d", n); for (int i = n - 1; i > 0; i--) printf(" %d", i); printf("\n"); } return 0; }
CPP
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; /** * * @author sukhdeep */ public class Test { public static void main(String arg[]) throws IOException { BufferedReader r=new BufferedReader(new InputStreamReader(System.in));...
JAVA
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
import java.io.*; import java.util.*; public class Main { StreamTokenizer in; PrintWriter out; int[] v; int[][] g; /** * @param args */ public static void main(String[] args) throws Exception { new Main().run(); } public class pairs implements Comparable<pairs> { int x; int y; public pairs(int ...
JAVA
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
import java.util.*; import java.io.*; public class BuggySorting { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); if(n == 1 || n == 2) System.out.println("-1"); else { for(int i = n; i >= 1; i--) { System.out.print(i + " "); } System.out.print...
JAVA
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
import sys n = int(raw_input()) if n <= 2: print -1 else: a = [3,2] for i in xrange(2,n): a.append(1) print ' '.join(map(str,a))
PYTHON
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
import java.util.*; public class r151d2a { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int[] array = new int[N]; for(int i = N; i >= 1; i--) array[N-i] = i; if(!runsortandcheck(array)) { System.out.println(-1); } else { for(int i = 0; ...
JAVA
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
#include <bits/stdc++.h> int main(void) { int i, n; while (scanf("%d", &n) != EOF) { if (n <= 2) { puts("-1"); } else if (n == 3) { puts("2 3 1"); } else { printf("100 99 "); for (i = 3; i <= n; i++) { printf("%d%c", i, i < n ? ' ' : '\n'); } } } return 0; }...
CPP
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
#include <bits/stdc++.h> using namespace std; int N; int main() { cin >> N; if (N <= 2) cout << -1 << endl; else { cout << N; for (int i = N - 1; i > 0; i--) cout << " " << i; cout << endl; } return 0; }
CPP
246_A. Buggy Sorting
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
2
7
import java.util.*; public class a { public static void main(String[]args){ Scanner sc = new Scanner(System.in); int n =sc.nextInt(); if(n<3){ System.out.println(-1); return; } for(int i=n;i>0;i--){ System.out.print(i+" "); } }}
JAVA