-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCryptopangrams.cpp
More file actions
67 lines (67 loc) · 1.71 KB
/
Cryptopangrams.cpp
File metadata and controls
67 lines (67 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define fastIO ios::sync_with_stdio(0); cin.tie(0);
ll prime(ll X, ll Y, ll N)
{
vector<bool>isPrime(N+1,true);
isPrime[0] = false;
isPrime[1] = false;
for(ll i = 2; i * i <= N; ++i) {
if(isPrime[i] == true) {
for(ll j = i * i; j <= N ;j += i)
isPrime[j] = false;
}
}
for(ll i=N;i>=0;i--)
{
if(isPrime[i] && Y%i==0 && X%i==0)
return i;
}
}
int main()
{
fastIO
int t;
cin>>t;
for(int z=1;z<=t;z++)
{
map<ll,ll>mp;
ll n,l;
cin>>n>>l;
vector<ll>A(l),res(l+1);
for(ll i=0;i<l;i++) cin>>A[i];
// cout<<prime(3292937,175597,n);
res[1] = prime(A[0],A[1],n);
res[0] = A[0]/res[1];
res[2] = A[1]/res[1];
for(ll i=2;i<l;i++)
res[i+1] = A[i]/res[i];
// for(auto i:res) cout<<i<<" ";
vector<ll>temp=res;
sort(temp.begin(),temp.end());
// for(auto i:temp) cout<<i<<" ";
int k=0;
for(ll i=0;i<temp.size();i++)
{
if(mp.find(temp[i])==mp.end())
mp.insert(mk(temp[i],k++));
}
// for(auto it=mp.begin();it!=mp.end();++it)
// cout<<it->first<<" "<<it->second<<"\n";
string ans="";
for(ll i=0;i<res.size();i++)
{
char ch=mp[res[i]]+65;
ans+=ch;
}
cout<<"Case #"<<z<<": "<<ans<<"\n";
}
}