Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int gcd(int a, int b){
- return a==0?b:gcd(b%a,a);
- }
- void insertionSort(int arr[], int n){
- int key, j;
- for(int i=1;i<n;i++){
- key = arr[i];
- j = i-1;
- while (j>=0 && arr[j]>key){
- arr[j+1] = arr[j];
- j--;
- }
- arr[j+1] = key;
- }
- }
- int findGCD(int arr[], int n){
- int high=0;
- for(int i=n-1;i>=0;i--){
- for(int j=i-1;j>=0;j--){
- int temp = gcd(arr[i], arr[j]);
- if(arr[j]<high){
- break;
- }else if(temp>high){
- high = temp;
- }
- }
- }
- return high;
- }
- int main(){
- int tc;
- scanf("%d", &tc);
- for(int i=1;i<=tc;i++){
- int n, product=1, high=0, check;
- scanf("%d", &n);
- int data[n];
- for(int j=0;j<n;j++){
- scanf("%d", &data[j]);
- }
- insertionSort(data, n);
- printf("Case #%d: %d\n", i, findGCD(data, n));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement