prompt
string
response
string
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << "=" << a << " ! "; err(++it, args...); } const long long N = 2e3 + 7, M = 1e9 + 7, inf = 2e18; string a[N], b[N]; l...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int N = 2005, M = 205; int n, m, fail[M]; char a[N][M], b[M][N]; int f[M][N]; void get_fail(int r) { for (int i = 2, j = 0; i <= m; ++i) { while (j > 0 && a[r][i] != a[r][j + 1]) j = fail[j]; if (a[r][i] == a[r][j + 1]) j++; fail[i] = j; } } int main()...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); long long base = 1e9 + 7, mod = 972663749; const int maxn = 2010, maxm = 210; string a[maxn], b[maxm]; map<long long, int> mp; int main() { ios::sync_with_stdio(0); int n, m; cin >> n >> m; for (...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const pair<int, int> P = {1e9 + 7, 1e9 + 9}, base = {29, 37}, base1 = {20180417, 20010201}; pair<int, int> operator+(pair<int, int> a, pair<int, int> b) { return pair<int, int>((a.first + b.first) % P.first, (a.second + b.secon...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; long long i, k, j, jj, l, s, t, a[223556], b[525789], c[223456], cc[2222][2222], n, m, d[22222], e, g[2222][2222]; string p[2222], q[2222], r; pair<long long, long long> x[445678]; int main() { cin >> n >> m; l = 1000000007; t = 1; k = 1; for (i = 0; i < 2222;...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
import java.io.*; import java.util.*; public class A2 { PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok; long MOD = 1000000007; public void go() throws IOExcepti...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; inline int add(int a, int b, int mod) { a += b; return a >= mod ? a - mod : a; } inline int sub(int a, int b, int mod) { a -= b; return a < 0 ? a + mod : a; } inline int mul(long long a, int b, int mod) { a *= b; return a >= mod ? a % mod : a; } const int mods[]...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int N = 2002; const int M = 202; char a[N][M], b[M][N]; long long ha[N], hb[N][M]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; for (int i...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T sqr(T x) { return x * x; } template <typename T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; } template <typename T> inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; } template <class T> inline do...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(name...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int N = 2005; const int M = 2010; char s1[M][M], s2[M][M]; unsigned long long dp1[M][M], dp2[M][M], prime = 3797, F[M * M]; int n, m; int main() { F[0] = 1; for (int i = 1; i < M * M; i++) F[i] = F[i - 1] * prime; scanf("%d %d", &n, &m); for (int i = 0; i < n;...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int N = 2003, M = 202; int n, m; char x[N][M], y[M][N]; bool check(int a, int b) { for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { if (x[i + a][j] != y[i][j + b]) return false; } } return true; } int main() { scanf("%d%d", &n, &m); ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int mo = 997; int n, m, AA[2010], BB[210][2010]; char A[2010][210], B[210][2010], tmp[210][210]; int main() { scanf("%d%d\n", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%s\n", A[i] + 1); for (int j = 1; j <= m; ++j) AA[i] = (AA[i] + (A[i][j] - 97 + 1) ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int num[5] = {131, 151, 191}; const int modo[5] = {200003, 300007, 400009}; int hash1[2005][5]; int equal[2005]; char a[1005]; char b[205][2005]; int hash2[2005][5]; int nums[5]; int final_hash1[2005][5]; int final_hash2[2005][5]; int hash3[2005][5]; int main() { in...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int inf = 129349823; const long long linf = 1ll * inf * inf; const int N = 2000 + 7; const int M = 1000000; const int multipleTest = 0; const double pi = acos(-1); long long F[M]; long long base = rand() % inf; int n, m; string s[N]; long long hash_row[N]; long long b...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
inp = raw_input N, M = map(int, inp().split()) g1 = [inp() for _ in range(N)] g2 = [inp() for _ in range(M)] global MOD, m25, msq26 MOD = 10**9 + 7 m26 = (26**M)%MOD msq26 = (m26**M)%MOD h1 = {} def hsh(s): m = 0 for ch in s: m = m*26%MOD m += ord(ch) - ord('a') return m%MOD def hsh2(s): ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const double PI = 3.14159265359; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<string> A(n), B(m); for (auto& s : A) cin >> s; for (auto& s : B) cin >> s; vector<vector<long long>> ah(n, vecto...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; template <class T> void chkmax(T &a, T b) { if (a < b) a = b; } template <class T> void chkmin(T &a, T b) { if (a > b) a = b; } const int inf = 0x3f3f3f3f; const long long linf = 2e18 + 100; const double eps = 1e-7; char s[2005][205], t[205][2005]; int a[2005], pw[2005]...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; const int N = 2050; int n, m; char c[N]; unsigned long long a[N], b[N][N], pw[N]; map<unsigned long long, int> tab; int main() { for (int i = pw[0] = 1; i < N; i++) pw[i] = pw[i - 1] * 27; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const long long p = 239; const long long mod = (long long)1e9 + 7; long long h1[2020], h[220][2020], st[2020]; string s[2020], t[220]; long long modd(long long a) { a %= mod; if (a < 0) a += mod; return a; } long long has(int i, int j1, int j2) { return modd(h[i][j2...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; char a[3010][3010], b[3010][3010]; long long n, m, f1[3010], f2[3010]; long long tmp, sum; void Hsh(char c) { tmp = (tmp * 127 + (c - 'a')) % 99873309; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (int...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const long long arr = 3e5; const long long base = 257; long long md = 1e9 + 100; long long hesh1[2010][2010], hesh2[2010][2010], h1[2010], h2[2010], step[arr], rstep[arr]; long long get(long long u, long long l, long long r) { return ((hesh2[u][r] - hesh2[u][l - 1]) %...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; long long st[40007]; char ta[2007][207], tb[207][2007]; long long hsha[2007], hshb[2007]; int main() { st[0] = 1; for (int i = 1; i < 40005; i++) st[i] = (30 * st[i - 1]) % 1000000007; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m;...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; constexpr int NMAX = 2002, MMAX = 202; constexpr int BASE = 29, MOD = 1e9 + 7; int N, M; char A[NMAX][MMAX]; char B[MMAX][NMAX]; int val_A[NMAX]; int val_B[NMAX]; int power[MMAX * MMAX]; void Do_Value_A() { int aux = M * M - 1; for (int i = 1; i <= M; ++i) for (int ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> char getc() { char ch = getchar(); while (ch < 'a' || ch > 'z') ch = getchar(); return ch; } const long long base = 137, mod = 1e9 + 7; std::map<long long, int> row1; const int maxn = 2010, maxm = 210; char g1[maxn][maxm], g2[maxm][maxn]; long long h1[maxn], h2[maxm][maxn]; int main() { ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int SZ = 100010; long long INF = 0x7FFFFFFF; const double EPS = 1e-8; char one[2010][2010], two[2010][2010]; long long mod = 1e9 + 7; int main() { { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { scanf(" %s", one[i]); } for ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int MAXLEN = 1e6; struct RH_single { static const unsigned long long B = 127; static const unsigned long long P = 1e9 + 7; static unsigned long long pow[MAXLEN]; static unsigned long long add(unsigned long long x, unsigned long long y) { return (x + y) % P...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; int n, m, B = 19260817, C = 1e9 + 7; char a[2020][220], b[220][2020]; unsigned long long hsha[2020], hshb[220][2020], hsa[2020], hsb[2020]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; unsigned long lo...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int N = 2020; long long pw[N * 202]; unordered_map<long long, int> hsh; char a[N][N], b[N][N]; int n, m, base = 31; void preCalc() { pw[0] = 1; for (int i = 1; i < N * 202; ++i) pw[i] = (pw[i - 1] * base) % 1000000000039LL; } int main() { preCalc(); scanf(...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100005; struct RH { static long long mod[2], mul[4]; static vector<long long> pm[4]; vector<string> s; int rw, cl; vector<vector<long long> > hs[2]; void init(vector<string>& s) { this->s = s; rw = (int)(s).size(), cl = (int)(s[0]).size...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\n"; err(++it, args...); } long long int po[2005], inv[2005], hvalue[2005]; long long int pro(long l...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; void get_Result(char map1[2000][200], char map2[200][2000], int N, int M) { int i, j, k, l; int recordj; int recordl; recordj = -1; l = 0; for (i = 0, j = 0; i < M; i++) { for (; j < N; j++) { recordl = -1; for (k = 0; k < M; k++) { for (...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; int n, m, i, j, l, k; char a[2005][205], b[205][2005]; bool check(int x, int y) { for (l = 0; l < m; l++) for (k = 0; k < m; k++) if (a[x + l][k] != b[l][k + y]) return 0; return 1; } int main() { scanf("%d%d", &n, &m); for (i = 0; i < n; i++) scanf("%s", ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int seed = 917; int expmod(int a, int b) { int rlt = 1; while (b) { if (b & 1) rlt = 1ll * a * rlt % mod; a = 1ll * a * a % mod; b >>= 1; } return rlt; } int calc_hash(char *s, int m) { int rlt = 0; for (int i = 0; i < ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; int n, m; char s[2055][255]; char t[255][2055]; const unsigned long long B = 1610612741, C = 805306457; const unsigned long long X = 104729, Y = 104173; pair<unsigned long long, unsigned long long> h[2055]; pair<unsigned long long, unsigned long long> c[2055]; pair<unsigned...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock() / CLOCKS_PER_SEC); long long n; cin >> n; ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int N = 2000 + 5; int n, m; struct hash_table { unsigned long long seed; unsigned long long Hash[N], temp[N]; void Set(unsigned long long num) { seed = num; } void work(char *s, int n) { temp[0] = 1; Hash[0] = 0; for (int i = 1; i <= n; i++) temp[i...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; inline int Gcd(int X, int Y) { return Y ? Gcd(Y, X % Y) : X; } inline long long Gcd(long long X, long long Y) { return Y ? Gcd(Y, X % Y) : X; } inline int Pow(int base, long long exp, int _mod) { int _ans = 1; for (; exp; exp >>= 1, base = (long long)base * base % _mod)...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; unsigned long long val(char x) { return x - 'a' + 1; } unsigned long long _hash(string &str) { unsigned long long res = val(str[0]); for (int i = 1; i < ((int)(str).size()); ++i) res = res * 29 + val(str[i]); return res; } int main() { ios_base::sync_with_stdio(fals...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; template <typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream& operator<<(ostream& os, vector<T> const& x) { os << "{ "; for (auto& y : x) os << y << " "; ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; vector<string> v, w; map<string, int> vis; int main() { int n, m; scanf("%d %d", &n, &m); string s; for (int i = 0; i < n; i++) { cin >> s; v.push_back(s); } for (int i = 0; i < m; i++) { cin >> s; w.push_back(s); } for (int i = 0; i < v.size...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vii = vector<pair<int, int>>; struct node { node *succ[26]; int num; node() { for (int i = 0; i < 26; ++i) succ[i] = nullptr; } }; vector<int> kmpPreprocessing(vector<int> &sub) { vector<int> b(sub.size() + 1...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; vector<string> v1, v2, v3(100005), v4(100005); long long x, y; string s; int main() { cin.tie(0); std ::ios ::sync_with_stdio(false); ; cin >> x >> y; for (int i = 0; i < x; i++) { cin >> s; v1.push_back(s); } for (int i = 0; i < y; i++) { cin >> s...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; string q[2001], p[2001]; long long n, m, i, j, x, y, c[2001][2001], t[2001][2001], ans1[2001], ans2[2001], ans3[2001], ans4[2001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; x = 1; y = 1; for (i = 0; i < 2001; i++) { for...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e3 + 10, M = 2e2 + 10, mod = 1e9 + 7, base = 31; char a[N][M], b[M][N]; int n, m; long long hasha[N][M], hashb[M][N], powbase[N * N]; void read() { cin >> n >> m; char ch; for (int i = 1; i <= n; i++) { ch = getchar(); for (int j = 1; j <=...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return a ? gcd(b % a, a) : b; } template <typename T> T lcm(T a, T b) { return (a / gcd(a, b)) * b; } bool is_down(char x) { return ('a' <= x && x <= 'z'); } bool is_upper(char x) { return ('A' <= x && x <= 'Z'); } bool is_digit(c...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int N = 255001; const long double PI = acos(-1); int n, m; char g1[2222][222]; char g2[222][2222]; pair<int, pair<int, int> > hsh[2222]; pair<int, pair<int, int> > hsh2[222][2222]; pair<int, pair<int, int> > getHash(int i) { if (hsh[i].first || hsh[i].second.first) ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; int m, n; string a1[2100], a2[2100]; pair<long long int, long long int> hashes1[2100], hashes2[2100]; long long int ans[2][1000000]; long long int pow1(long long int a, long long int b, long long int m) { if (b < 1e6 and m == 1000000007 and ans[0][b] != -1) return ans[0][...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2100; const long long base = 1e8 + 3; const long long BASE1 = 27; const long long BASE2 = 31; int n, m; long long f1[maxn][maxn], f2[maxn][maxn], pw1[maxn], pw2[maxn]; string a[maxn], b[maxn]; long long get(long long f[][maxn], int x1, int y1, int x2, int y...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; struct H { long long MOD, BASE; H(long long MOD, long long BASE) : MOD(MOD), BASE(BASE) {} long long fastpow(long long num, long long p) { if (p == 0) return 1; if (p & 1) return (num % MOD * fastpow(num, p - 1)) % MOD; long long a = fastpow(num, p / 2); ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline long long read1(...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int N = 2005; const int M = 205; const int mod = 998244853; const unsigned long long p1 = 5557; const int p2 = 2333; struct node { unsigned long long x; int y; node() {} node(unsigned long long x, int y) : x(x), y(y) {} friend node operator+(node a, node b) ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; int debug_num = 0; unordered_map<string, bool> mp; vector<string> v; char mapp[210][2010]; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; string s = ""; string tp = ""; for (int i = 1; i <= m; ++i) { cin >> tp; v.push_back(tp); s ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int PRIME_BASE = 719; const long long PRIME_MOD = 1110111110111ULL; void mod(long long& h) { if (h >= PRIME_MOD) h -= PRIME_MOD; } long long mulmod(long long a, long long b) { long long res = 0; while (a > 0) { if (a & 1) { res += b; mod(res); ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int n, m; map<vector<vector<char> >, int> M; vector<vector<char> > s, c, d; void print() { for (int i = 0; i < m; i++, cout << "\n") for (int j = 0; j < m; j++) { cout << d[i][j]; } } int main() { ios_base::sync_with_stdio(0); ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const long long int inf = 9e18; long long int fast_expo(long long int a, long long int n) { long long int ans = 1; while (n > 0) { if (n % 2 == 1) ans = (ans * a) % 1299827; a = (a * a) % 1299827; n = n / 2; } return ans; } long long int hashcompute(stri...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000; const int MAXM = 200; const int B = 31; char mat[MAXM + 1][MAXN + 1]; string str; unsigned long long hsh2[MAXM + 1][MAXN + 1]; unsigned long long hsh1[MAXN + 1]; map<unsigned long long, int> mp; int main() { int i, j, n, m; ios::sync_with_stdio(fa...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; long long mi[400010], ni[400010], x; char a[400010]; int n, m; map<pair<long long, long long>, int> s; void pre(long long x, long long len) { long long i; mi[0] = 1; for (i = 1; i < 400010; i++) mi[i] = mi[i - 1] * 31 % 1000007; ni[0] = 1; for (i = 1; i < 400010; ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } template <typename T, typename U> inline ostream &operator<<(ostream &_out, const pair<T, ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int mod = 1e9 + 7; const double eps = 1e-6; const int N = 2e3 + 7; unsigned long long h1[N], h2[N][N]; char s[N][N], t[N][N]; int n, m; void init() { for (int i = 1; i <= n; i++) { unsigned long long h = 0; for (int j = 1; j <= m; j++...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(), m = scanner.nextInt(); char[][] c1 = new char[n][m], c2 = new char[m][n]; for (int i = 0; i < n; i++) c1[i] = scann...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
n, m = [int(x) for x in input().split()] list1 = [] list2 = [] for i in range(n): list1.append(input()) for j in range(m): list2.append(input()) list3 = [] for i in range(n - m + 1): y = "" for j in range(m): y += list1[j + i] list3.append(y) list4 = [] for i in range(n - m + 1): y = ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> #pragma GCC optimize("O3") const long long INF = 0x3f3f3f3f3f3f3f3f; const long long llinf = -(1LL << 61); const int inf = (1 << 30); const int nmax = 1e5 + 50; const int mod = 1e9 + 7; using namespace std; int n, m, i, j, k; set<vector<vector<char> > > st; map<vector<vector<char> >, int> mp; v...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int l, int r) { return l + rng() % (r - l + 1); } const int mn = 2e3 + 10; char a[mn][mn], b[mn][mn]; int m, n; unsigned long long h[mn][mn], g[mn][mn]; unsigned long long b1 = 31, b2 = 37, pw1[mn]...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const long long N = 2001, M = 201, mod = 1e9 + 7; long long n, m; long long _hash[M * M], Pow[M * M], cal1[N], cal2[N]; string a[N], b[M]; long long solve(string res) { long long x = res.length(); for (long long i = 0; i < x; ++i) { if (i == 0) _hash[i] = res[...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { static BufferedReader in; static PrintWriter out; static StringTokenizer tok; class RollingHash { int m; long q = 1000000007L; long ...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
import java.io.*; import java.sql.Array; import java.util.*; public class Main { public static void main(String[] args) throws Exception { // Reader.init(new File("greater.in")); Reader.init(System.in); // PrintWriter out = new PrintWriter(new FileWriter("output.txt")); PrintWrit...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; template <typename TF> void debug(ostream &out, TF const &f) { out << f << std::endl; } template <typename TF, typename... TR> void debug(ostream &out, TF const &f, TR const &...rest) { out << f << " "; debug(out, rest...); } using ll = long long; using ull = unsigned...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int N = 2200; const int MOD = 1e9 + 9; int dp[N], S[N], T[N]; char s[N][N], t[N][N]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1); for (int i = 1; i <= m; i++) scanf("%s", t[i] + 1); for (int i = 1; i <= n;...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> int debug_num = 0; using namespace std; const int MAXN = 2000 + 5; const int MAXM = 200 + 5; char A[MAXN][MAXM]; long long Ahash[MAXN]; long long Ahash2[MAXN]; long long buffhash[MAXN]; char B[MAXM][MAXN]; long long Bhash[MAXN]; long long Bhash2[MAXN]; void show(int N, int M) { for (int i = (...
Problem: The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map ...
#include <bits/stdc++.h> using namespace std; const int N = 2002, M = 202; int n, m; string A[N], B[M]; vector<int> cols; long long hshA[N][M]; long long hshB[M][N]; long long pwr[N]; void buildHash() { pwr[0] = 1; for (int i = 1; i <= n; i++) pwr[i] = pwr[i - 1] * 37 % 1000000007; for (int i = 0; i < n; i++) ...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import javax.swing.plaf.basic.BasicInternalFrameTitlePane; import java.io.*; import java.math.*; import java.nio.Buffer; import java.sql.SQLSyntaxErrorException; import java.util.*; import java.text.*; import java.util.regex.Pattern; import java.util.stream.Collectors; public class Main { public static long g...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } int main() { ios::sync_with_stdio(false); cin.tie(0); long long p, q, b; int n; cin >> n; while (n--) { cin >> p >> q >> b; long long x = p / gcd(p, q); long long y = q / ...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; long long p, q, b; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } int main() { int n; cin >> n; while (n--) { scanf("%lld%lld%lld", &p, &q, &b); long long d = gcd(p, q); p /= d; q /= d; for (int i = 0; i < 6...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { private static long gcd(long a, long b){ if(b>a){ long t=a; a=b; b=...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int p, long long int q) { if (p == 0) { return q; } return gcd(q % p, p); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int p, q, b; for (int i = 0; i < n; i++) { ci...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import java.util.*; import java.math.*; import java.io.*; public class A{ static class Reader // fast reader class taken from geeksforgeeks { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; pu...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import java.io.*; import java.util.*; import java.text.*; import java.lang.*; import java.math.BigInteger; import java.util.regex.*; public class Myclass { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n=in.nextIn...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; using namespace std; long long gcd(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return a; a %= b; return gcd(b, a); } int main() { long long t; scanf("%lld", &t); while (t--) { long long n, i, j, k, p, q, b, g, stat = 1, lp; scanf("%l...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } long long gcd(long long x, long ...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import java.io.*; import java.util.*; public class CODEFORCES { private InputStream is; private PrintWriter out; int time = 0, DP[], start[], end[], dist[], black[], MOD = (int) (1e9 + 7), arr[], weight[][], x[], y[], parent[]; int MAX = 100000, N, K; long red[]; ArrayList<Integer>[] amp; ArrayLis...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import sys import math ini = lambda: int(sys.stdin.readline()) inl = lambda: [int(x) for x in sys.stdin.readline().split()] def solve(): p, q, b = inl() if p == 0: return True g = math.gcd(p, q) p //= g q //= g if q == 1: return True return pow(b, 64, q) == 0 n = ini() f...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import java.io.*; import java.util.*; public class C { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); new Solution().solve(in, out); out.close(); } } class Solution { public void solve(Input...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; const int N = 5e6 + 10; int num[N], isprime[N]; int cnt = 0; long long gcd(long long p, long long q) { return q ? gcd(q, p % q) : p; } void jprime() { for (int i = 2; i <= 5e6; i++) { if (!num[i]) isprime[cnt++] = i; for (int j = 0; j < cnt && isprime[j] * i <= 5e...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; int i, j, m, n; long long p, q, b, temp; long long gcd(long long a, long long b) { long long t; if (a > b) { t = a; a = b; b = t; } if ((b % a) == 0) return a; return gcd(b % a, a); } int main() { scanf("%d", &n); for (i = 1; i <= n; i++) { sca...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import java.util.*; import java.io.*; public class Test5{ public static void main(String[] z) throws Exception { Scanner s = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); long k = Long...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader inp = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); So...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; const int N = 103305; int n; int tot; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } int main() { int cases; scanf("%d", &cases); for (int iii = 1; iii <= cases; ++iii) { long long p, q, base; scanf("%I64d%I64d%I64d", &...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Arrays; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStreamReader; public class FiniteOrNot { public static void mai...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import sys input() for line in sys.stdin: p,q,b=[int(x) for x in line.split()] sys.stdout.write('Infinite\n' if p*pow(b,64,q)%q else 'Finite\n')
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { long long p, b, q; scanf("%lld%lld%lld", &p, &q, &b); if (p == 0) { puts("Finite"); continue...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
for __ in xrange(int(raw_input())): p, q, b = map(int, raw_input().split()) print("Infinite" if p * pow(b, 64, q) % q else "Finite")
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import sys input() out = [] for line in sys.stdin: p,q,b=[int(x) for x in line.split()] out.append('Infinite' if p*pow(b,64,q)%q else 'Finite') print('\n'.join(out))
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Scanner; import java.util.StringTokenizer; /** * * @author paras */ public class finiteornotfinite { static class FastRe...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; int n; long long a, b, q; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } bool check(long long x, long long y) { if (y % x == 0) return 1; long long t = gcd(x, y); if (t == 1) return 0; return check(x / t, t); } void doit(...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { while (a % b != 0) { long long c = a % b; a = b; b = c; } return b; } int main() { int n; long long p, q, b; cin >> n; while (n--) { int f = 1; scanf("%I64d %I64d %I64d", &p, &q, &b); long long ...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int n; long long p, q, b; long long penyebut, pembilang, fpb; scanf("%d", &n); while (n--) { scanf("%I64d%I64d%I64d", &p, &q, &b); fpb = gcd(p, q); ...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int x, long long int y) { long long int ma = max(x, y); long long int mi = min(x, y); if (ma % mi == 0) return mi; return gcd(mi, ma % mi); } int main() { ios::sync_with_stdio(0); int n; cin >> n; for (int N = 0; N < n; N++) { ...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
#include <bits/stdc++.h> using namespace std; long long max(long long x, long long y) { return x > y ? x : y; } long long min(long long x, long long y) { return x < y ? x : y; } long long gcd(long long p, long long q) { if (q == 0) return p; return gcd(q, p % q); } bool check(long long b, long long p) { long long...
Problem: You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite number of numerals after the decimal point. It is also possible that a ...
n = int(input()) ans = [] while n: n += -1 p, q, b = map(int, input().split()) if p * pow(b, 62, q) % q: ans.append("Infinite") else: ans.append("Finite") for _ in ans: print(_)