###### 【数学水题】【TOJ4113】【 Determine X】

yuebai has a long sequence of integers A1,A2,,AN.
He also has such a function:

F(x)=i=1N(Aix+Aimodx)
x is a positive integer, which determined by yuebai.
Now he wants to know the minimum value of the function.

SB了

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
using namespace std;
const int maxn=1000000+5;
int N;
int A[maxn],a[maxn];
int MAX;
long long sum=0;
void input()
{
memset(A,0,sizeof(A));
memset(a,0,sizeof(a));
cin>>N;
MAX=-1;
sum=0;
for(int i=1;i<=N;i++)
{
scanf("%d",&A[i]);
a[A[i]]++;
if(A[i]>MAX) MAX=A[i];
sum+=A[i];
}
for(int i=1;i<=MAX;i++)
{
a[i]=a[i]+a[i-1];
}
}
void solve()
{
long long ans=1LL<<30;
long long tt=0,g;
for(int i=1;i<=MAX;i++)
{
int x=i;tt=0;
for(int t=2*x;t-1<=MAX;t+=x)
{
int p=t-1;
long long k=(long long)(a[p]-a[p-x])*(long long)(p/x);
tt=tt+k;
g=p;
}
tt=tt+(long long)(a[MAX]-a[g])*(long long)(MAX/x);
tt=tt+sum-tt*(long long)x;
if(tt<ans) ans=tt;
}
cout<<ans<<endl;
}
int main()
{
//  freopen("a.in","r",stdin);
int T;
cin>>T;
while(T--)
{
input();
solve();
}
}


#### HDU 2161 Primes （判断素数的水题）

2018-01-05 20:47:14

#### Hduoj2065 【数学】【水题】

2014-10-18 10:49:52

#### 非常可乐 （广搜（简单倒水问题））

2017-05-03 11:26:56

#### ural 1057 Amount of Degrees（数位dp）

2014-01-01 16:11:41

#### poj入门水题--宽搜（bfs）题 1979 1562 2386 3278

2016-11-13 21:06:55

#### codevs天梯 递归第一次 水题

2017-02-05 12:27:10

#### P1603 斯诺登的密码

2016-10-18 17:12:26

#### ∇的数学含义

2015-09-15 15:39:59

#### LeetCode-9 Palindrome Number(判断是否为回文int型)

2015-04-18 09:28:24

#### 迷之水题 SDUT 3044

2015-08-08 20:58:36

## 不良信息举报

【数学水题】【TOJ4113】【 Determine X】