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} ...
随机推荐
- zlog 程序日志的库 交叉编译(Linux生成ARM库,观察执行步骤)
1. zlog 是个很好的写程序日志的库,功能比较强大,上手快. 2. 下载地址:https://github.com/bmanojlovic/zlog 3. cd 到文件夹下,对 autogen.s ...
- QRCode二维码生成方案及其在带LOGO型二维码中的应用(2)
原文:QRCode二维码生成方案及其在带LOGO型二维码中的应用(2) 续前:QRCode二维码生成方案及其在带LOGO型二维码中的应用(1) http://blog.csdn.net/johnsu ...
- WPF Binding妙处-既无Path也无Source
<Window x:Class="XamlTest.Window12" xmlns="http://schemas.microsoft.com/win ...
- TCPClient组件和TCPServer组件的主要方法和属性
IdTCPClient属性1 : IOHandler 如果有相应的输入/输出操作,那么IOHandler相对应的组件或接口将提供一个虚拟/抽象的输入/输出接口给相应的网络连接2 : Intercept ...
- linux下计划任务学习记录
0x01 计划任务简介 linux 中计划任务主要分为”循环执行”和”只执行一次”两种,分别对应的时 crond 服务 和 atd 服务: 0x02 只执行一次的计划任务 0x02.1 atd 服务说 ...
- WPF 鼠标在图片Image上悬停时切换更改设置图片源Source
// 无效的写法,图片不会被切换 <Image Margin="0,0,0,0" Width="50" Height="50" Sou ...
- 元素命名空间中的“MvcBuildViews”无效
原文:元素命名空间中的"MvcBuildViews"无效 症状描述: VS2010打开项目时提示:"元素 命名空间"http://schemas.microso ...
- Win10《芒果TV》商店版更新v3.1.4.0:适配Xbox手柄B键后退、手机支持暗色主题不伤眼
在双十一全球剁手节.光棍节欢庆之际,<芒果TV>UWP版迅速更新v3.1.4版,适配Xbox手柄B键全局后退,支持手机切换暗色主题,优化并解决启动卡顿等问题. 芒果TV UWP V3.1. ...
- Delphi中流对象的应用
Delphi的流对象(TStream的派生对象)有如下读写函数: function Read(var Buffer; Count: Longint): Longint;function Write(c ...
- Linux下的软件安装
在线安装 APT:advanced packaging Tool,Debian及其派生的发行版的软件包管理工具,包含以apt-开头的多个工具,如apt-get,apt-cache,apt-cdrom ...