题目链接

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

我交了题后,疯狂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. linux下怎么修改mysql的字符集编码

    安装完的MySQL的默认字符集为 latin1 ,为了要将其字符集改为用户所需要的(比如utf8),就必须改其相关的配置文件:由于linux下MySQL的默认安装目录分布在不同的文件下:不像windo ...

  2. HITICS || 2018大作业 程序人生 Hello's P2P

    摘  要 本文通过分析一个hello.c的完整的生命周期,从它开始被编译,到被汇编.链接.在进程中运行,讲解了Linux计算机系统执行一个程序的完整过程. 关键词:操作系统,进程,程序的生命周期 目 ...

  3. shell脚本,awk数组之如何处理多个文件。

    [root@localhost | > file [root@localhost - | > file1 [root@localhost awk]# cat file [root@loca ...

  4. SimpleWeather APP

    参考 iOS 7 Best Practices; A Weather App Case Study: Part 1/2 iOS 7 Best Practices; A Weather App Case ...

  5. iOS开发遇见的坑之二:工程文件中插件和自身工程命名冲突

    在升级cocoapod后,我重新管理了一下工程,其实也就是把各个类分类进行管理 类似于这样 然后编译就发现不能运行 1.其中一个错误是工程文件缺失,根据提示添加进来进行 2.有一个是pch的相对路径变 ...

  6. document节点的一些个性属性

    <ol> <li>document.head:返回文档的< head>节点:</li> <li>document.body:返回文档的< ...

  7. C语言实现链表及其操作

    #include <stdio.h> #include <stdlib.h> //定义节点 typedef struct Node { int data; struct Nod ...

  8. 蓝牙学习 (8)配对raspberryPi和SensorTag CC2650

    在上一篇中,用raspberryPi能够扫描到Ti SensorTag. 但是没有获得更多的数据,并且发现sensor Tag并没有回复scan request. https://blog.csdn. ...

  9. verilog behavioral modeling--blocking and nonblocking

                                                                                                 BLOCKIN ...

  10. cache支持三种pre-fetch方式:normal/pre-fetch1/pre-fetch2-way1/pre-fetch-way2

    1.normal fetch  ----fetch 1 cache line once 2. pre-fetch mode one ---- fetch 3 cache line once 3.pre ...