题目链接

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

我交了题后,疯狂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_109_切片补充和list函数

    #切片补充 a=[1,2,3,4,5,6,7,8] print(a[::2])#隔一个取一个元素 [1, 3, 5, 7] print(a[::-1])#将列表或元祖颠倒过来 [8, 7, 6, 5, ...

  2. shell脚本,实现奇数行等于偶数行。

    请把如下字符串stu494e222fstu495bedf3stu49692236stu49749b91转为如下形式:stu494=e222fstu495=bedf3stu496=92236stu497 ...

  3. CS193p Lecture 8 - Protocols, Blocks and Animation

    一.协议(Protocols) 1. 声明协议 @protocol Foo <Xyzzy, NSObject> // ... @optinal // @required //... @en ...

  4. 一次线上mysql死锁分析

    一.现象 发运车次调用发车接口时发生异常,后台抛出数据库死锁日志. 二.原因分析 通过日志可以看出事务T1等待 heap no 8的行锁 (X locks 排他锁) 事务T2持有heap no 8的行 ...

  5. if else elif 用法和区别

    1.If语句:“如果条件为真,执行子句中的代码."始终包含以下部分: if关键字: 条件(即求值为True或False的表达式): 冒号: 在下一行开始,缩进的代码块(称为if子句) 例如: ...

  6. grep理解

    http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856896.html部分摘录于此 grep与正规表达式  字符类 字符类的搜索:如果我想要搜 ...

  7. 使用VS2015编写驱动时出现的部分错误以及解决方法

    前几日在github上下载了一个Windows驱动的demo,原本想着直接下载下来打开解决方案就可以用,没想到一编译,出现了奇奇怪怪的Error,部分Error网上也没什么好的解决办法,对我这个从未深 ...

  8. Python中摘要算法MD5,SHA1讲解

    摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通常用16进制的字符串表示).摘要算法就是通过摘要函数f()对任意长度的数据data计算出固定长度的摘要di ...

  9. slave_net_timeout 问题一则

    [背景]   对一套数据库集群进行5.5升级到5.6之后,alter.log 报warning异常. 2015-02-03 15:44:51 19633 [Warning] Storing MySQL ...

  10. Eclipse如何创建模拟器

    Eclipse如何创建模拟器下载地址:http://developer.android.com/sdk/index.html#downloadJDK安装包: 1, 打开安卓模拟器控制台(windows ...