All submissions for this problem are available.
Read problems statements in English, Mandarin Chinese and Russian as well.
Given an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that
LCM of all integers in that subarray is equal to the product of all integers in that subarray.
For a subarray Ai,Ai+1...Aj where 1 ≤ i < j ≤ N to be valid: LCM(Ai,Ai+1...Aj) should be equal to Ai*Ai+1*...*Aj. You have to print the size of the largest valid subarray.
If no subarray satisfies output -1.
Note:A single element is not considered a subarray according to definition in this problem.
First line contains T, the number of testcases. Each testcase consists of N in one line followed by N integers in next line.
For each testcase, print the required answer in one line.
- 1 ≤ T ≤ 50
- 2 ≤ N ≤ 105
- 1 ≤ Ai ≤ 106
Input: 3 2 7 2 4 2 2 3 4 3 2 2 4 Output: 2 2 -1
Example case 1.LCM(2,7)=2*7. Therefore, subarray A1 to A2 satisfies.
Example case 2.The subarrays A2 to A3 and A3 to A4 are the maximum size possible.
Example case 3.No subarray will satisfy.
Warning: Use fast input/output. Large input files. Solutions may not pass in slower languages.
Update: Time limit for python=10s
|Tags||cook50, darkshadows, dynamic-programming, lcm, math, medium|
|Time Limit:||2.5 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.