题目链接

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

我交了题后,疯狂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. python小括号( )与中括号 [ ]

    在python中小括号()表示的是tuple元组数据类型,元组是一种不可变序列. >>> a = (1,2,3) >>> a (1, 2, 3) >>& ...

  2. 国庆集训 || Wannafly Day4

    链接:https://www.nowcoder.com/acm/contest/205#question 一场题面非常 有趣 但是题目非常 不友好的比赛 QAQ L.数论之神   思维(?) 题意:求 ...

  3. PAT (Basic Level) Practise (中文)-1028. 人口普查(20)

    PAT (Basic Level) Practise (中文)-1028. 人口普查(20)   http://www.patest.cn/contests/pat-b-practise/1028 某 ...

  4. Python-DB接口规范

    threadsafety 线程安全级别.threadsafety 这是一个整数, 取值范围如下: 0:不支持线程安全, 多个线程不能共享此模块 1:初级线程安全支持: 线程可以共享模块, 但不能共享连 ...

  5. c# DateTime常用用法

    参考:http://sqlyuju.com/c-datetime-hh-hh-qubie.html https://www.cnblogs.com/xiongxiaobai/p/5282827.htm ...

  6. mem之读操作调式总结(跟入栈出栈有关)

    现象: 1.当case比较复杂的时候(含有for循环对mem进行读/写) 发现for循环时总是有汇编指令不执行跳过去了,(其实是汇编不熟和指令太多无法理智分析指令了). 事实是指令是对的,但执行错了( ...

  7. aggregate和annotate使用

    aggregate和annotate方法的使用场景 Django的aggregate和annotate方法属于高级查询方法,主要用于组合查询,是Django高手们必需要熟练掌握的.当我们需要对查询集( ...

  8. php expat+DOM+SimpleXML XML读取

    XML 文件 将在我们的例子中使用下面的 XML 文件: <?xml version="1.0" encoding="ISO-8859-1"?> & ...

  9. java 中 image 和 byte[] 相互转换

      java 中 image 和 byte[] 相互转换可恶的…………其实也挺好的 只是把好不容易写出来的东西记下来,怕忘了…… 下面,我来介绍一个简单的 byte[] to image, 我们只需要 ...

  10. Spring注解@Component、@Repository、@Service、@Controller

    @Service用于标注业务层组件 @Controller用于标注控制层组件(如struts中的action) @Repository用于标注数据访问组件,即DAO组件 @Component泛指组件, ...