Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- // build sieve
- bool used[10010] = {};
- vector<int> primes;
- for (int i = 2; i <= 10000; ++i) {
- if (used[i]) continue;
- primes.push_back(i);
- for (int j = i+i; j <= 10000; j += i)
- used[j] = true;
- }
- int T;
- scanf("%d", &T);
- for (int t = 1; t <= T; ++t) {
- // input
- int n, l;
- scanf("%d%d", &n, &l);
- assert(n <= 10000);
- int val[l], P[l+1];
- for (int i = 0; i < l; ++i)
- scanf("%d", &val[i]);
- // find suitable starting point
- int st;
- for (int i = 0; i < l; ++i) {
- int sol = 0;
- for (auto p : primes) {
- if (val[i]%p == 0 && val[i+1]%p == 0)
- sol = sol == 0 ? p : -1;
- }
- if (sol > 0) {
- st = i;
- P[i] = val[i]/sol;
- break;
- }
- }
- // go left and right
- for (int i = st+1; i < l+1; ++i)
- P[i] = val[i-1]/P[i-1];
- for (int i = st-1; i >= 0; --i)
- P[i] = val[i]/P[i+1];
- // create map to characters
- map<int, char> M;
- for (int i = 0; i < l+1; ++i)
- M[P[i]] = 0;
- char cnt = 'A';
- for (auto &m : M) // &m = allows editing directly in the map
- m.second = cnt++;
- printf("Case #%d: ", t);
- for (int i = 0; i < l+1; ++i)
- printf("%c", M[P[i]]);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement