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} ...
随机推荐
- iOS开发之应用首次启动显示用户引导
这个功能的重点就是在如何判断应用是第一次启动的. 其实很简单 我们只需要在一个类里面写好用户引导页面 基本上都是使用UIScrollView 来实现, 新建一个继承于UIViewController ...
- C# 特性的使用
using ClassLibrary;using System;using System.Collections.Generic;using System.Linq;using System.Refl ...
- C#有哪几种定时器
1.定义在System.Windows.Forms里2.定义在System.Threading.Timer类里3.定义在System.Timers.Timer类里 System.Windows.For ...
- SQL Server上唯一的数据库集群:负载均衡、读写分离、容灾(数据零丢失、服务高可用)
SQL Server上唯一的数据库集群:负载均衡.读写分离.容灾(数据零丢失.服务高可用).审计.优化,全面解决数据库用户问题.一键安装,易用稳定,性价比高,下载链接:http://www.zheti ...
- C#字符串类型
C#字符串类型(string)是一种引用类型,是System.String的别名,表示Unicode字符串. 两种表示方法: 1.“C#” 直接用双引号括起来. 2.使用@,@“c:\test”,可以 ...
- Devart Blog
How to combine data from several sources using SQL and VirtualQueryhttp://blog.devart.com/how-to-com ...
- 声谱预测网络(Tacotron2)
整个特征预测网络是一个带有注意力机制(attention)的seq2seq网络. 编码器-解码器(Encoder-Decoder)结构 在原始的编码器-解码器结构中,编码器(encoder)输入一个序 ...
- 《KVM虚拟化技术实战和原理解析》读书笔记(十几篇)
第一章和第二章 第一章 虚拟化和云计算 Saas(软件即服务):将已经部署好的软件作为一种服务来提供,比如:Google Docs, Google Apps Paas(平台即服务):将开发环境作为一种 ...
- CWnd和HWND的区别(hWnd只是CWnd对象的一个成员变量,代表与这个对象绑定的窗口)
所有控件类都是CWnd类的派生类,CWnd的所有成员函数在控件类中都可以使用.在MFC中,CWnd类是一个很重要的类,它封装了Windows的窗口句柄HWND.在Windows编程中, ...
- Delphi使用android的NDK是通过JNI接口,封装好了,不用自己写本地代码,直接调用
一.Android平台编程方式: 1.基于Android SDK进行开发的第三方应用都必须使用Java语言(Android的SDK基于Java实现) 2.自从ndk r5发布以后, ...