# Digital game continued

Source: Internet
Author: User
Document directory
• Problem description
• Input
• Output
• Sample Input
• Sample output
Continued time limit for digital games: 12000/4000 ms (Java/other) memory limit: 65535/32768 K (Java/other) total submission (s): 152 accepted submission (s): 50 Font: times New Roman | verdana | georgiafont size, he wants to calculate the maximum common divisor of two numbers A and B.
Because these two numbers are very large, the Mavericks split the number a into N numbers. The result of multiplying the N numbers is a, and B is split into M numbers, similarly, the product of the number of M is equal to the value of B. Tom can't wait to calculate the maximum common number of the two numbers. Can you help him this time? If the result exceeds 9 digits, the last 9 digits are output. The input has multiple groups of data.
The first line contains a positive integer N (1 <=n <= 1000 ).
The second line contains n positive integers less than 1 000 000 000 separated by spaces. Their product is.
The third row contains a positive integer m (1 <= m <= 1000 ).
The fourth row contains M positive integers less than 1 000 000 000 separated by spaces. Their product is B. Output outputs the maximum common divisor of A and B. If the result exceeds 9 digits, the last 9 digits are output. Sample Input
`32 3 524 546 2 3 4113358572 83391967 82350229961 1091444 8863`
Sample output
`101000012028`
View code

`#include<stdio.h>#include<string.h>#include<stdlib.h>unsigned long long gcd( long long n, long long m ){  return m ? gcd(m,n%m): n;          }unsigned long long a[1010],s1;unsigned long long d[1010],s2;int main( ){  int N, M;    unsigned long long dd[1010];  while( scanf("%d",&N) != EOF)  {     s1 = 1;     for( int i = 1; i <= N; i++)     {          scanf("%lld",&a[i]);     }     s2 = 1;     scanf("%d",&M);     for( int i = 1; i <= M; i++)     {          scanf("%lld",&d[i]);     }     int flag = 0;     for( int i = 1; i <= N; i++)     {        for( int j = 1; j <= M; j++)        {           s2  = gcd(a[i],d[j]);           s1 *= s2;                 if( s1 >= 1000000000 )             s1 %= 1000000000, flag = 1;           a[i] /= s2;           d[j] /= s2;        }                  }     if( flag )     {        printf("%09I64u\n",s1%1000000000);               }     else       printf("%I64u\n",s1);                       }        }`

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.