greedy math number theory *1400

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll a[1000000],b[1000000];
int main()
{
    ll tc;
    cin>>tc;
    while(tc--)
    {
        ll n;
        map<ll,ll>v;
        ll k=0;
        cin>>n;

        for(int i=0; i<n; i++)
        {
            cin>>a[i];
        }
        for(int i=0; i<n; i++)
        {
            k=k+a[i];
            a[i]=k;
            v[a[i]]++;

        }
        ll j=0;
        for(int i=1; i*i<=k; i++)
        {
            if(k%i==0)
            {
                b[j++]=i;
                if(i!=k/i)
                {
                    b[j++]=k/i;
                }
            }
        }
        ll sum=0;

        sort(b,b+j);

        for(int i=0; i<j; i++)
        {
            ll h=0;
            sum=0;
            for(int m=1; m<=(k/b[i]); m++)
            {

                ll d=0;
                d=b[i]*m;
                if(v[d]==1)
                {
                    sum++;

                }
                else
                {
                    h=-1;
                    break;
                }
            }
            if(h==0)
                break;
        }
        cout<<n-sum<<endl;
    }
}


Comments

Submit
0 Comments
More Questions

1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza
731A - Night at the Museum
742A - Arpa’s hard exam and Mehrdad’s naive cheat
1492A - Three swimmers
1360E - Polygon
1517D - Explorer Space
1230B - Ania and Minimizing
1201A - Important Exam
676A - Nicholas and Permutation
431A - Black Square
474B - Worms
987B - High School Become Human