"Number theory", "Violence" bzoj4052 [cerc2013]magical GCD

Source: Internet
Author: User

Consider adding a number to a collection whose gcd are either unchanged or become an approximate of the original GCD. So the different gcd have only log ones.

So for each location, maintain a table that stores all the different gcd from this location forward and its initial position, and then violence updates the answer, anyway this table won't be very long.

#include <cstdio> #include <algorithm> #include <cstring>using namespace std; #define N 100001typedef Long long ll;typedef pair<ll,int> point; Point Table[101],t[101];int t,n,en,e2;ll gcd (ll A,ll b) {return (!b)? A:GCD (b,a%b);} int main () {ll x;scanf ("%d", &t); T;--T)  {  ll ans=0;  en=0;  scanf ("%d", &n);  for (int i=1;i<=n;++i)    {    scanf ("%lld", &x);    for (int j=1;j<=en;++j)      table[j].first=gcd (table[j].first,x);    Table[++en]=make_pair (x,i);    Sort (table+1,table+1+en);    e2=0;    for (int j=1;j<=en;++j)      if (Table[j].first!=table[j-1].first)        t[++e2]=table[j];    En=e2;    memcpy (table+1,t+1,sizeof (point) *e2);    for (int j=1;j<=en;++j)      Ans=max (ans,table[j].first* (LL) (i-table[j].second+1));    }  printf ("%lld\n", ans);  } return 0;}

"Number theory", "Violence" bzoj4052 [cerc2013]magical GCD

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.