Codeforces 757B:Bash's Big Day(分解因子+Hash)
http://codeforces.com/problemset/problem/757/B
题意:给出n个数,求一个最大的集合并且这个集合中的元素gcd的结果不等于1。
思路:一开始把素数表打出来,发现有9k+个数,不能暴力枚举。发现O(sqrt(n)*n)似乎可行,就枚举因子,然后出现过的因子就在Hash[]加1,最后枚举素数表里的元素,找出现次数最多的,因为那些数都可以映射在素数表里面。注意最少的ans是1.
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
using namespace std;
#define INF 0x3f3f3f3f
#define N 100010
typedef long long LL;
int prime[N], num[N], cnt;
int Hash[N]; void biao() {
for(int i = ; i <= ; i++) {
int tmp = sqrt(i); bool flag = ;
for(int j = ; j <= tmp; j++) {
if(i % j == ) {
flag = ; break;
}
}
if(!flag) prime[++cnt] = i;
}
} int main() {
biao();
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d", &num[i]);
Hash[num[i]]++;
int tmp = sqrt(num[i]);
for(int j = ; j <= tmp; j++) {
if(num[i] % j == ) {
Hash[j]++;
if(j != num[i] / j) Hash[num[i] / j]++;
}
}
}
int ans = ;
for(int i = ; i <= cnt; i++) {
if(ans < Hash[prime[i]]) {
ans = Hash[prime[i]];
}
}
cout << ans << endl;
return ;
}
Codeforces 757B:Bash's Big Day(分解因子+Hash)的更多相关文章
- Codeforces 757B - Bash's Big Day(分解因子+hashing)
757B - Bash's Big Day 思路:筛法.将所有因子个数求出,答案就是最大的因子个数,注意全为1的特殊情况. 代码: #include<bits/stdc++.h> usin ...
- Codeforces 757B. Bash's Big Day GCD
B. Bash's Big Day time limit per test:2 seconds memory limit per test:512 megabytes input:standard i ...
- Codeforces 1058 D. Vasya and Triangle 分解因子
传送门:http://codeforces.com/contest/1058/problem/D 题意: 在一个n*m的格点中,问能否找到三个点,使得这三个点围成的三角形面积是矩形的1/k. 思路: ...
- uva 993 Product of digits (贪心 + 分解因子)
Product of digits For a given non-negative integer number N , find the minimal natural Q such tha ...
- D. Almost All Divisors(数学分解因子)
其实这题并不难啊,但是分解因子的细节一定要小心. \(比如样例48,2是因子说明24也是因子,也就是说假如x存在\) \(那么x一定是因子中的最小数乘上最大数\) \(那我们现在去验证x是否存在,先拿 ...
- 【codeforces 757B】 Bash's Big Day
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- Codeforces 1058 D. Vasya and Triangle(分解因子)
题目:http://codeforces.com/contest/1058/problem/D 题意:有一个大小为N*M的矩阵内,构造一个三角形,使面积为(n*m)/k.若存在输出三个顶点(整数). ...
- 【Codeforces 757B】 Bash's big day
[题目链接] 点击打开链接 [算法] 若gcd(s1,s2,s3....sk) > 1, 则说明 : 一定存在一个整数d满足d|s1,d|s2,d|s3....,d|sk 因为我们要使|s|尽可 ...
- Codeforces E. Bash Plays with Functions(积性函数DP)
链接 codeforces 题解 结论:\(f_0(n)=2^{n的质因子个数}\)= 根据性质可知\(f_0()\)是一个积性函数 对于\(f_{r+1}()\)化一下式子 对于 \[f_{r+1} ...
随机推荐
- windows添加本地文件托管到新增github库
新增repositoy.登录gitHub,并点击“New Reposoitory” 写入名字 之后点击“create resposity” \ 按照上图中的步骤可以完成.以下为完成步骤. 2. 在本 ...
- WPF中的Application类。
原文:WPF中的Application类. Application对象用的名称空间是system.windows 1.手动创建Application对象步骤. 1.1).把项目中的App.Xaml文件 ...
- ORACLE 时间加减操作
DATE和timestamp类型都可以进行加减操作.可以对当前日期加年.月.日.时.分.秒,操作不同的时间类型,有三种方法: 1 使用内置函数numtodsinterval增加小时,分钟和秒2 加一个 ...
- SQLite 的版本问题
原文:SQLite 的版本问题 在SQLite官方网站上的下载包真可以看花眼.不同的.net版本,还有不同的平台,开发和发布时需要加以注意. 在网上搜了搜,早有人注意到了. 关于在.Net开发中使用S ...
- 一步一步造个IoC轮子(二),详解泛型工厂
一步一步造个Ioc轮子目录 一步一步造个IoC轮子(一):Ioc是什么 一步一步造个IoC轮子(二):详解泛型工厂 一步一步造个IoC轮子(三):构造基本的IoC容器 详解泛型工厂 既然我说IoC容器 ...
- IDisposeable 最佳实现
public class MyClass : IDisposable { #region 变量声明 // 指向外部非托管资源 private IntPtr handle; // 此类使用的其它托管资源 ...
- ARTS 1.21 - 1.25
每周一个 Algorithm,Review 一篇英文文章,总结一个工作中的技术 Tip,以及 Share 一个传递价值观的东西! Algorithm: 学习算法 题目:3Sum Closest 解题过 ...
- C#串口控制舵机、arduino源码 及C#源码及界面
原文 C#串口控制舵机.arduino源码 及C#源码及界面 1.舵机原理简介 控制信号由接收机的通道进入信号调制芯片,获得直流偏置电压.它内部有一个基准电路,产生周期为20ms,宽度为1.5ms的基 ...
- ML:吴恩达 机器学习 课程笔记(Week9~10)
Anomaly Detection Recommender Systems Large Scale Machine Learning
- C语言的setlocale和localtime函数(C++也可用)
Example 1234567891011121314151617181920212223242526272829303132 /* setlocale example */ #include < ...