var stdin = process.openStdin();
var data = [];
var letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
var BCTABNTb_TEKCT = `2
103 31
217 1891 4819 2291 2987 3811 1739 2491 4717 445 65 1079 8383 5353 901 187 649 1003 697 3239 7663 291 123 779 1007 3551 1943 2117 1679 989 3053
10000 25
3292937 175597 18779 50429 375469 1651121 2102 3722 2376497 611683 489059 2328901 3150061 829981 421301 76409 38477 291931 730241 959821 1664197 3057407 4267589 4729181 5335543`;
data = BCTABNTb_TEKCT.toString().split(/\r\n|\r|\n/);
var tests = data[0];
for(var i = 0; i<tests; i++) {
var s1 = data[i*2+1].split(' ');
var s2 = data[i*2+2].split(' ').reverse();
var lastPrime = parseInt(s1[0]);
var primesCount = parseInt(s1[1]);
var givenPrimes = s2;
var sourceList = [];
var tempList = [];
for(var j = 0; j<primesCount; j++) {
var n = s2[j];
var nums = findPrimes(n);
if(nums.length == 1) {
nums.push(n/nums[0]);
}
tempList.push(nums);
}
for(var k = 0; k<primesCount; k++) {
if(k>0) {
var arr1 = tempList[k];
var arr2 = tempList[k-1];
var sameArr = arr1.filter(element => arr2.includes(element));
var same = sameArr[0];
if(arr2[0] == same) sourceList.push(arr2[1]);
else sourceList.push(arr2[1]);
sourceList.push(same);
if(k==primesCount-1) {
if(arr1[0] == same) sourceList.push(arr1[1]);
else sourceList.push(arr1[0]);
}
}
}
for(var m = 0; m<sourceList.length; m++) {
if(sourceList[m] == sourceList[m+1]) {
sourceList.splice(m+1, 1);
m--;
}
}
sourceList.reverse();
var sorted = sourceList.filter((v,i) => sourceList.indexOf(v) == i);
sorted.sort((a, b) => a - b);
var msg = [];
for(var h = 0; h<sourceList.length; h++) {
for(var p = 0; p<sorted.length; p++) {
if(sorted[p] == sourceList[h]) msg.push(letters[p]);
}
}
console.log('Case #'+(i+1)+': '+msg.join(''));
}
function findPrimes(num) {
var integer = num,
primeArray = [],
isPrime;
for(i = 2; i <= integer; i++){
if (integer % i==0) {
for(var j = 2; j <= i/2; j++) {
if(i % j == 0) {
isPrime = false;
} else {
isPrime = true;
}
}
if (isPrime == true) {
integer /= i
primeArray.push(i);
}
}
}
var result = [];
for (var k = 0; k < primeArray.length; k++) {
result.push(primeArray[k]);
}
return result;
}
About Online Node Compiler
Try our Online Node Compiler (Version Node v6.11.2) to Edit, Run, and Share your Node Code directly from your browser. This online development environment provides you the latest version Node v6.11.2.
How to use Online Node Compiler?
Write and Execute Code
- Write your program (or, paste it) directly under the "Source Code" tab.
- If you want to save your program, go to the "Project" menu and save it.
- You can directly execute your program without saving it by clicking on on "Execute" button.
User Input
The latest version of Coding Ground allows to provide program input at run time from the termnial window exactly the same way as you run your program at your own computer. So simply run a program and provide your program input (if any) from the terminal window available in the right side.
Online Node Compiler: Keyboard Shortcuts
The following are the keyword shortcut of this Online Node Compiler:
Shortcut | Description |
⌘ + Enter | Run the program |
⌘ + S | Save Project (Login Required) |
⇧ + ⌘ + S | Save As Project |
⌘ + P | New Project |
⌘ + G | Share Project |
⌘ + Z | Undo Editing |
⌘ + Y | Redo Editing |
⌘ + A | Select All Text |
⌘ + X | Cut Selected Text |
⌘ + C | Copy Selected Text |
⌘ + V | Paste Copied Text |
⌘ + F | Search Text |
⌘ + ⌥ + F | Replace Text |
Shortcut | Description |
Ctrl + Enter | Run the program |
Ctrl + S | Save Project |
Shift + Ctrl + S | Save As Project |
Ctrl + G | Share Project |
Ctrl + Z | Undo Editing |
Ctrl + Y | Redo Editing |
Ctrl + A | Select All Text |
Ctrl + X | Cut Selected Text |
Ctrl + C | Copy Selected Text |
Ctrl + V | Paste Copied Text |
Ctrl + F | Search Text |
Ctrl + H | Replace Text |
Online Node Compiler: Save and Share Node Code (Project)
Save Node Project Online
You can save your Node Project with us so that you can access this project later on. To save a project you will need to create a login Id with us. So before you save a project, please create a login Id using a link given at the top right corner of this page.
Share Node Project Online
You can use this feature to share your Node Code with your teachers, classmates and colleagues. Just click Share Button and it will create a short link, which can be shared through Email, WhatsApp or even through Social Media. A shared link will be deleted if it has been passive for almost 3 months.
More Features of Online Node Compiler
- Theme – You can change the current editor's theme from the "Editor Theme" option under "Settings" menu.
- Font Size – You can change the font size of the editor /compiler from from the "Font Size" option under "Settings" menu.
- Tab Size – You can change the tab size from the "Tab Size" option under "Settings" Menu.
- Show/Hide Line Numbers – You can show/hide the line number with the code from the "Show Line Numbers" or "Hide Line Numbers" option under "Settings" Menu.
- And, many more.
Benefits of Using Online Node Compiler
There are several benefits of using the Online Node Compiler to run your Node code:
- Platform independence: You can run your code from any device without taking care of operating systems.
- Convenience: You don't need to install anything for using this.
- No setup required: There is no need for additional setup to run your code.
- Updated version: Our online compiler/editors/terminals are the latest up-to-date.