Last Updated on March 30, 2022 by Ria Pathak
Concepts Used:
Mathematics
Difficulty Level:
Medium
Problem Statement (Simplified):
For a given array of integers print the total number of integers which divides all the array elements and are less than or equal to the first element.
See original problem statement here
Test Case:
Solving Approach:
1) We iterate from
1
to the first element (arr[0]
) of the array and count all the numbers which divide all the array elements.
2) We print the count of total such numbers after all iterations are completed.
Example:
1) Let array
A
be[8,12,14,16,24,36]
2) As8
is our first element, so we’ll check for all elements from1
to8
.
3) In this range, only1
, and2
divides all the elements, so2
is our answer.
Solutions:
#includeint main() { int test; scanf("%d", &test); while(test--){ int n; scanf("%d", &n); int hero[n]; for(int i=0; i 1; i--){ if(hero[0]%i==0){ int flag = 1; for(int j=1; j
#includeusing namespace std; int main() { int test; cin>>test; while(test--){ int n; scanf("%d", &n); int hero[n]; for(int i=0; i >hero[i]; int i, count=0; for(i = hero[0]; i>1; i--){ if(hero[0]%i==0){ int flag = 1; for(int j=1; j
import java.util.*; import java.io.*; public class Main { public static void main(String args[]) throws IOException { Scanner sc = new Scanner(System.in); int test = sc.nextInt(); while(test!=0){ int n = sc.nextInt(); int hero[] = new int[n]; for(int i=0; i1; i--){ if(hero[0]%i==0){ int flag = 1; for(int j=1; j
[forminator_quiz id="736"]
This article tried to discuss the concept of Mathematics. Hope this blog helps you understand and solve the problem. To practice more problems on Mathematics you can check out MYCODE | Competitive Programming.