CA Loves GCD (bc#78 1002) (Hdu 5656)

Source: Internet
Author: User

CA Loves GCDaccepts:135submissions:586Time limit:6000/3000 MS (java/others)Memory limit:262144/262144 K (java/others)Problem description
CA likes to be a love party and people of excellent with ♂, so he also very much like gcd (please enter in the Input method GCD get CA like gcd reason). Now he has n different numbers, and each time he chooses a number (at least one number) to find out all the GCD and put it back. In order to not be bored, the CA will select each of the different options, CA want to know all the gcd he got. We think that the two methods are different when and only if one of the numbers is selected in one of the options, and not selected in the other method.
Enter a description
First lineTT, indicating that there isTT Group data. NextTT group data, first row of each group of data an integerNN, which represents the number of CAs, and the next lineNN integersA_iA?I?? Represents each number of CAs.1 \le T \le 50,~1 \le N \le 1000,~1 \le a_i \le 10001≤T≤50,  1≤n≤ 1000, 1≤ A   ? i ?? ≤1000   
Output description
10000000710000000 7The result of the modulo. 
Input sample
222 431 2 3
Output sample
810



DP (i) (j): Number of GCD for the first I number of J 1.DP (I+1) (j) +=DP (i) (j)
2.DP (i+1) (GCD (j,v)) +=DP (i) (j)
3. DP (0) (0) =1
(
i:1~1000
j:1~1000)
#include <cstdio>#include<cstring>intdp[1010][1010];Const intmod=1e8+7;intgcdintXintY) {returny==0? X:GCD (y,x%y);}inta[1010];intgc[1010][1010];intMain () { for(intI=0; i<= +; i++)    {         for(intj=i;j<= +; j + +) {Gc[j][i]=gc[i][j]=gcd (I,J); }    }    intT; scanf ("%d",&T);  while(t--) {memset (DP,0,sizeof(DP)); dp[0][0]=1; intn,v; scanf ("%d",&N);  for(intI=1; i<=n;i++) scanf ("%d",&A[i]);  for(intI=1; i<=n;i++)        {             for(intj=0; j<= +; j + +) {Dp[i][j]= (dp[i][j]+dp[i-1][J])%MOD; Dp[i][gc[j][a[i] ]= (dp[i][gc[j][a[i]]]+dp[i-1][J])%MOD; }        }        Long Longans=0;  for(Long Longj=1; j<= +; j + +) ans= (ans+dp[n][j]*j)%MOD; printf ("%lld\n", ans); }    return 0;}
View Code

CA Loves GCD (bc#78 1002) (Hdu 5656)

Contact Us

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.