hdu5514 principle of non-2 Chijong

Source: Internet
Author: User

1 /*2 13 126 2230928704 210 330 390 462 510 546 570 690 714 770 798 858 910 966 1122 1155 1190 1254 1326 1330 1365 1430 1482 1518 1610 1785 17  94 1870 1938 1995 2002 2090 2145 2210 2346 2415 2470 2530 2618 2622 2805 2926 2990 3003 3094 3135 3230 3315 3458 3542 3705 3795 3910 3927 4186 4370 4389 4485 4522 4641 4845 4862 5005 5187 5313 5434 5474 5865 6118 6279 6545 6555 6578 6783 7106 7 293 7315 7735 8151 8211 8398 8602 8645 8855 9177 9614 9867 10166 10465 10659 11305 11362 12155 12597 12903 13585 13685 144  21 14858 15249 15295 16445 17017 17043 17765 19019 20995 21505 22287 23023 24035 24871 25415 28405 29393 30107 33649 35581 37145 39767 46189 52003 55913 62491 81719 965775 */6#include <cstdio>7#include <queue>8#include <cstring>9#include <iostream>Ten#include <cstdlib> One#include <algorithm> A#include <vector> -#include <map> -#include <Set> the#include <ctime> -#include <cmath> -#include <cctype> - #defineN 10000 + #defineLL Long Long - #defineU unsigned + using namespacestd; A intcas=1, T; at intn,m,a[n+Ten],d[n+Ten],dn,v[n+Ten],c[n+Ten]; - intgcdintAintb) - { -     returnb==0? A:GCD (b,a%b); - } - voidFAC () in { -dn=0; to     intX=SQRT (m) +0.5; +      for(intI=1; i<=x;i++) -     { the         if(m%i==0) *         { $d[dn++]=i;Panax Notoginsengd[dn++]=m/i; -         } the     } +Sort (d,d+DN); A } the intMain () + { -     //freopen ("1.in", "w", stdout); $     //freopen ("1.in", "R", stdin); $     //freopen ("Out1", "w", stdout); -scanf"%d",&T); -      while(t--) the     { -memset (V,0,sizeof(v));//the number of times to goWuyiMemset (c,0,sizeof(c));//the number of times that have gone thescanf"%d%d",&n,&m); -         Set<int>G; Wu          for(intI=0; i<n;i++) {scanf ("%d", a+i); G.insert (GCD (m,a[i]%m)); } - FAC (); About          for(Set<int>::iterator It=g.begin (); It!=g.end (); it++)//initialization, *it a multiple of a time to go $         { -              for(intj=0; j<dn;j++)if(d[j]% *it==0) v[j]=1; -         } -LL ans=0; A         //for (int i=0;i<dn;i++) printf ("%d", D[i]);p rintf ("\ n"); +          for(intI=0; i<dn;i++) the         { -             if(V[i]) $             { the                 intDif=v[i]-c[i];//D[i] The number of times to go-has been gone = number of times to go now theans+= (LL) m* (m/d[i]-1)/2*dif; the                  for(intj=i+1; j<dn;j++)if(d[j]%d[i]==0) C[j]+=dif;//D[i] The multiples of d[i] have gone through the dif times, so c[j]+=dif the             } -         } inprintf"Case #%d:%lld\n", cas++, ans); the     } the     //printf ("Time=%.3lf", (double) clock ()/clocks_per_sec); About     return 0; the}
View Code

hdu5514 principle of non-2 Chijong

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.