题目链接

题目就是找每个数的最小素因子,然后递归除,本来没啥问题,结果今天又学习了个新坑点。

我交了题后,疯狂CE,我以为爆内存,结果是,我对全局数组赋值,

如果直接赋值,会直接在exe内产生内存,否则只会在运行时才分配内存。

 #include <bits/stdc++.h>
using namespace std; const int maxn = 1e7 + 5e6 + ; //线性素数筛
int prime[],num_prime = ;
int vis[maxn];
void is_prime(int N)
{
for(int i=;i<N;i++)
{
if(!vis[i])
{
prime[num_prime++] = i;
vis[i] = i;
}
for(int j=;j<num_prime&&i*prime[j]<N;j++)
{
vis[i*prime[j]] = prime[j];
if(!(i%prime[j]))
{
break;
}
}
}
return;
}
int a[];
int fp[maxn]; int main()
{
int n; scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
int g = a[];
for(int i = ; i <= n; i++) g = __gcd(g, a[i]);
for(int i = ; i <= n; i++) a[i] /= g;
memset(fp, , sizeof(fp));
is_prime(maxn);
int maxlen = ;
for(int i = ; i <= n; i++)
{
while(a[i] > )
{
fp[vis[a[i]]]++;
maxlen = max(maxlen, fp[vis[a[i]]]);
int tmp = vis[a[i]];
while(a[i] % tmp == )
{
a[i] = a[i] / tmp;
}
if(a[i] == ) break;
}
}
if(maxlen == ) printf("-1\n");
else printf("%d\n", n - maxlen);
return ;
}
/*
4
18 27 45 30
*/

Codeforces Round #511 (Div. 2) C. Enlarge GCD的更多相关文章

  1. Codeforces Round #511 (Div. 2)-C - Enlarge GCD (素数筛)

    传送门:http://codeforces.com/contest/1047/problem/C 题意: 给定n个数,问最少要去掉几个数,使得剩下的数gcd 大于原来n个数的gcd值. 思路: 自己一 ...

  2. Codeforces Round #511 (Div. 2) C. Enlarge GCD (质因数)

    题目 题意: 给你n个数a[1]...a[n],可以得到这n个数的最大公约数, 现在要求你在n个数中 尽量少删除数,使得被删之后的数组a的最大公约数比原来的大. 如果要删的数小于n,就输出要删的数的个 ...

  3. Codeforces Round #511 (Div. 2)

    Codeforces Round #511 (Div. 2) #include <bits/stdc++.h> using namespace std; int n; int main() ...

  4. Codeforces Round #511 (Div. 2):C. Enlarge GCD(数学)

    C. Enlarge GCD 题目链接:https://codeforces.com/contest/1047/problem/C 题意: 给出n个数,然后你可以移除一些数.现在要求你移除最少的数,让 ...

  5. 2018.9.21 Codeforces Round #511(Div.2)

    只写了AB,甚至还WA了一次A题,暴露了蒟蒻的本质=.= 感觉考的时候有好多正确或和正解有关的思路,但是就想不出具体的解法或者想的不够深(长)(怕不是过于鶸) 话说CF的E题怎么都这么清奇=.= A. ...

  6. C. Enlarge GCD Codeforces Round #511 (Div. 2)【数学】

    题目: Mr. F has nn positive integers, a1,a2,…,an. He thinks the greatest common divisor of these integ ...

  7. Codeforces Round #554 (Div. 2)-C(gcd应用)

    题目链接:https://codeforces.com/contest/1152/problem/C 题意:给定a,b(<1e9).求使得lcm(a+k,b+k)最小的k,若有多个k,求最小的k ...

  8. Codeforces Round #347 (Div.2)_A. Complicated GCD

    题目链接:http://codeforces.com/contest/664/problem/A A. Complicated GCD time limit per test 1 second mem ...

  9. Codeforces Round #651 (Div. 2) A. Maximum GCD(数论)

    题目链接:https://codeforces.com/contest/1370/problem/A 题意 有 $n$ 个数大小分别为 $1$ 到 $n$,找出两个数间最大的 $gcd$ . 题解 若 ...

随机推荐

  1. Dubbo中的监控和管理

    一.Dubbo中的监控 1.原理 原理:服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心. 2.搭建监控服务 3.修改配置文件 修改注册中心的地址: 注意:这个 ...

  2. Apache Commons Configuration的应用

    Apache Commons Configuration的应用 Commons Configuration是一个java应用程序的配置管理工具.可以从properties或者xml文件中加载软件的配置 ...

  3. Spring框架context的注解管理方法之二 使用注解注入基本类型和对象属性 注解annotation和配置文件混合使用(半注解)

    首先还是xml的配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...

  4. WebAssembly MDN简单使用

    MDN 就是通过编译器编译完成c后生成的胶水代码 引入js 就能直接调用定义在c或者c++中的函数了 c代码如下: #include <stdio.h> #include <stdl ...

  5. 【动态规划】bzoj1044: [HAOI2008]木棍分割

    需要滚动优化或者short int卡空间 Description 有n根木棍, 第i根木棍的长度为Li,n根木棍依次连结了一起, 总共有n-1个连接处. 现在允许你最多砍断m个连接处, 砍完后n根木棍 ...

  6. MySQL 资料库概论与MySQL 安装

    本文来自:https://www.breakyizhan.com/sql/5648.html 1. 储存与管理资料 储存与管理资料一直是资讯应用上最基本.也是最常见的技术.在还没有使用电脑来管理你的资 ...

  7. tkinter学习-文本框

    阅读目录 Entry 输入框 Text 文本框 Entry: 说明:输入控件,用于显示简单的文本内容 属性:在输入框中用代码添加和删除内容,同样也是用insert()和delete()方法 from ...

  8. 【实验吧】guess next session&&FALSE&&NSCTF web200&&程序逻辑问题

      guess next session源码: <?php session_start(); if (isset ($_GET['password'])) { if ($_GET['passwo ...

  9. Web自动化Selenium2环境配置中Selenium IDE的安装

    下载的firefox32.0的版本,但是在附件组件中只有selenuim IDE button,本以为这个就是selenium IDE插件,自以为是的后果就是把自己坑了.并且像一些selenium I ...

  10. 00048_this关键字

    1.this调用构造方法 (1)构造方法之间的调用,可以通过this关键字来完成: (2)构造方法调用格式 this(参数列表); (3)小案例 class Person { // Person的成员 ...