#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+;
int a[N];
int n;
bool prime(int x) {//判断是否为质数
for(int i = ; i*i <= x; i++) {
if(x%i == ) return false;
}
return true;
}
ll solve(int x) {
vector<int>b;
ll ans = ;
for(int i = ; i <= n; i++) {
if(a[i] == && b.size() < x) b.push_back(i);//存放位置
if(b.size() == x) {
for(int j = ; j < b.size(); j++) {
ans += (ll)abs(b[j]-b[x/]);
}
b.clear();
}
}
return ans;
}
int main() {
int sum = ;
scanf("%d",&n);
for(int i = ; i <= n; i++) {
scanf("%d",a+i);
sum += a[i];
}
if(sum == ) {
printf("-1\n");
return ;
}
ll ans = 0x3f3f3f3f3f;
for(int i = ; i <= sum; i++) {
if(sum%i==&&prime(i)) {//此处用质因子优化,不加优化也行。
ans = min(ans,solve(i));
}
}
printf("%lld\n",ans);
return ;
}

最新文章

  1. USACO翻译:USACO 2012 JAN三题(1)
  2. C#预编译指令之#region
  3. Spring IOC容器中注入bean
  4. atitit查询表修改表字段没反应--解锁锁定的表
  5. 让Tomcat支持中文文件名
  6. Oracle自动增长的序列号
  7. Web页面布局方式小结
  8. centos7.2中文乱码解决办法
  9. UE4实现描边效果
  10. CentOS 7 常用命令大全
  11. C# 视频多人脸识别的实现
  12. Leetcode 题解 First Missing Positive
  13. Docker 指定容量
  14. python正则表达式贪婪与非贪婪模式
  15. mybatis 于 hibernate区别
  16. node.js学习之post文件上传 (multer中间件)
  17. maven的部署安装
  18. 使用Django完成CRM管理系统
  19. setsockopt 详解
  20. 作业派NABCD的特点分析

热门文章

  1. iMacros 入门教程-基础函数介绍(1)
  2. linux find命令mtime/atime/ctime +n -n n 全网最正确的总结
  3. 剑指offer-面试题55-平衡二叉树-递归
  4. sum用法
  5. GHO文件安装到Vmware的两种姿势
  6. 修改Linux中ssh协议中的默认端口号22
  7. Elasticsearch启动、停止脚本
  8. sql查询如何将A表数据name字段对应B表name字段得到对应的B表id主键然后添加A到表usel_id中
  9. VSCode添加git bash作为默认终端
  10. cat基础用法