mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			53 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p>
 | 
						|
 | 
						|
<p>An array <code>arr</code> is called <strong>product equivalent</strong> if <code>prod(arr) == lcm(arr) * gcd(arr)</code>, where:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>prod(arr)</code> is the product of all elements of <code>arr</code>.</li>
 | 
						|
	<li><code>gcd(arr)</code> is the <span data-keyword="gcd-function">GCD</span> of all elements of <code>arr</code>.</li>
 | 
						|
	<li><code>lcm(arr)</code> is the <span data-keyword="lcm-function">LCM</span> of all elements of <code>arr</code>.</li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p>Return the length of the <strong>longest</strong> <strong>product equivalent</strong> <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<div class="example-block">
 | 
						|
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,1,2,1,1,1]</span></p>
 | 
						|
 | 
						|
<p><strong>Output:</strong> <span class="example-io">5</span></p>
 | 
						|
 | 
						|
<p><strong>Explanation:</strong> </p>
 | 
						|
 | 
						|
<p>The longest product equivalent subarray is <code>[1, 2, 1, 1, 1]</code>, where <code>prod([1, 2, 1, 1, 1]) = 2</code>, <code>gcd([1, 2, 1, 1, 1]) = 1</code>, and <code>lcm([1, 2, 1, 1, 1]) = 2</code>.</p>
 | 
						|
</div>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<div class="example-block">
 | 
						|
<p><strong>Input:</strong> <span class="example-io">nums = [2,3,4,5,6]</span></p>
 | 
						|
 | 
						|
<p><strong>Output:</strong> <span class="example-io">3</span></p>
 | 
						|
 | 
						|
<p><strong>Explanation:</strong> </p>
 | 
						|
 | 
						|
<p>The longest product equivalent subarray is <code>[3, 4, 5].</code></p>
 | 
						|
</div>
 | 
						|
 | 
						|
<p><strong class="example">Example 3:</strong></p>
 | 
						|
 | 
						|
<div class="example-block">
 | 
						|
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,1,4,5,1]</span></p>
 | 
						|
 | 
						|
<p><strong>Output:</strong> <span class="example-io">5</span></p>
 | 
						|
</div>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>2 <= nums.length <= 100</code></li>
 | 
						|
	<li><code>1 <= nums[i] <= 10</code></li>
 | 
						|
</ul>
 |