[Lyft Level 5 Challenge 2018 - Elimination Round][Codeforces 1033D. Divisors]
题目链接:1033D - Divisors
题目大意:给定\(n\)个数\(a_i\),每个数的约数个数为3到5个,求\(\prod_{i=1}^{n}a_i\)的约数个数。其中\(1 \leq n \leq 500 , 1 \leq a_i \leq 2\cdot 10^{18}\)。
题解:考虑约数个数公式,可以发现对于任意的\(a_i\),有\(a_i=\left\{\begin{matrix}
p^2\\
p^3\\
p^4\\
p_1\cdot p_2
\end{matrix}\right.\)
其中前三种情况可以直接通过二分来找出时候有满足条件的\(p\),若存在符合条件的\(p\),则用\(map\)记录更新\(p\)的指数,否则\(a_i\)一定为两不同质数的积,将其记录到\(b_i\)中
接下来对于每个\(b_i\),遍历所有的\(a_j\),若存在这样的\(j\),使得\(1<gcd(b_i,a_j)<b_i\),则\(gcd(b_i,a_j)\)必为其中的一个质数,从而可以求出\(p_1,p_2\)的值并更新其指数,若找不到这样的\(j\),将其记录到\(c_i\)中
可以发现,在\(C\)中的数一定是由两个不同质数组成的,且没有数和他恰好有一个质因子。因此对于任意的\(a_j(j\neq i)\),有\(gcd(c_i,a_j)=\left\{\begin{matrix}
1\\
c_i
\end{matrix}\right.\),即\(a_j\)与\(c_i\)互质或者与之相等。因此这时只需要对每个不同的\(c_i\)判断有多少数与他相同并计算贡献就好。由于没有其它的数与\(c_i\)有相同质因子,因此\(c_i\)的两个质因子肯定是没有出现过的,设与\(c_i\)相同的数的个数为\(cnt\),将答案乘上\((cnt+1)\cdot (cnt+1)\)就好了。
#include<bits/stdc++.h>
using namespace std;
#define N 501
#define LL long long
#define MOD 998244353
LL INF=9e18;
LL n,a[N],b[N],c[N];
map<LL,LL>f;
LL Sqrt(LL n,LL k)
{
LL l=,r=n;
while(l<r)
{
LL mid=(l+r+)/2ll;
LL res=,K=k;
while(K--)
{
if(res>INF/mid)
{res=INF;break;}
res*=mid;
}
if(res>n)r=mid-;
else l=mid;
}
return l;
}
LL gcd(LL x,LL y){return y?gcd(y,x%y):x;}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
LL xx=;
scanf("%I64d",&a[i]);
for(LL k=;k>=;k--)
{
LL p=Sqrt(a[i],k);
LL res=,K=k;
while(K--)res*=p;
if(res==a[i]){f[p]+=k,xx=;break;}
}
if(xx)continue;
b[i]=a[i];
}
for(LL i=;i<=n;i++)if(b[i])
{
LL xx=;
for(LL j=;j<=n;j++)
{
if(j==i)continue;
LL g=gcd(b[i],a[j]);
if(g== || g==b[i])continue;
xx=,f[g]++,f[b[i]/g]++;
break;
}
if(!xx)c[i]=b[i];
}
LL ans=;
for(LL i=;i<=n;i++)if(c[i])
{
LL cnt=;
for(LL j=;j<=n;j++)
if(c[i]==c[j] && j!=i)cnt++,c[j]=;
ans*=cnt*cnt,ans%=MOD;
}
for(auto p:f)ans*=p.second+,ans%=MOD;
printf("%I64d\n",ans);
fflush(stdout);
return ;
}
[Lyft Level 5 Challenge 2018 - Elimination Round][Codeforces 1033D. Divisors]的更多相关文章
- Lyft Level 5 Challenge 2018 - Elimination Round
A. King Escape 签. #include <bits/stdc++.h> using namespace std; ], y[]; int f1(int X, int Y) { ...
- Lyft Level 5 Challenge 2018 - Elimination Round翻车记
打猝死场感觉非常作死. A:判一下起点和终点是否在其两侧即可. #include<iostream> #include<cstdio> #include<cmath> ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) B 1075B (思维)
B. Taxi drivers and Lyft time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)---ABC
A---The King's Race http://codeforces.com/contest/1075/problem/A 题意: 一个人在\((1,1)\), 一个人在\((n,n)\), 现 ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) C. The Tower is Going Home(思维+双指针)
https://codeforces.com/contest/1075/problem/C 题意 一个宽为1e9*1e9的矩阵中的左下角,放置一个车(车可以移动到同一行或同一列),放置一些墙,竖的占据 ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)
A. The King's Race 签. #include <bits/stdc++.h> using namespace std; #define ll long long ll n, ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) A. The King's Race
http://codeforces.com/contest/1075/problem/A On a chessboard with a width of nn and a height of nn, ...
- Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记
夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...
随机推荐
- 2018-2019-2 网络对抗技术 20165221 Exp3 免杀原理与实践
2018-2019-2 网络对抗技术 20165221 Exp3 免杀原理与实践 基础问题回答 杀软是如何检测出恶意代码的? 主要依托三种恶意软件检测机制. 基于特征码的检测:一段特征码就是一段或者多 ...
- PHP 常用知识点
@多台服务器共享 session 方案用户量很大,单台 Redis 根本就放不下怎么办?服务器端分布式存储了(Redis 集群. Memcached 集群),既然是分布式,那么就必须保证用户每次请求都 ...
- MSYS 编译 nginx rtmp-module
1. 下载源码 http://hg.nginx.org/nginx nginx-c74904a17021.zip https://github.com/arut/nginx-rtmp-module n ...
- 【intern】最长公共子串、编辑距离、KMP 等
这可能是一个很长的blog…… # from https://blog.csdn.net/justheretobe/article/details/51764587 #!/usr/bin/env py ...
- 【easy】257. Binary Tree Paths 二叉树找到所有路径
http://blog.csdn.net/crazy1235/article/details/51474128 花样做二叉树的题……居然还是不会么…… /** * Definition for a b ...
- 学习 razor pages 指南
这是一个系列,我打算把此人的系列翻译一下,学习技术的同时,顺便提高一下英文水平. 原文地址:https://www.learnrazorpages.com/ 前言 欢迎来学习 razor pages ...
- idea工具maven生命周期clean,compile,install,package区别
idea工具maven projects里面有9种生命周期,今天刚好遇到,顺便分享下自己的理解.生命周期是包含在一个项目构建中的一系列有序的阶段.最常用的两种打包方法:一:clean,package( ...
- kmp算法 模板
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...
- Linux搭建NodeJs环境
文件下载与解压 文件下载 wget https://npm.taobao.org/mirrors/node/v6.10.3/node-v6.10.3-linux-x64.tar.xz 如果要下载最新版 ...
- ollydbg入门记录
1.软件窗口说明 OllyDBG 中各个窗口的名称如下图.简单解释一下各个窗口的功能, 反汇编窗口:显示被调试程序的反汇编代码,标题栏上的地址.HEX 数据.反汇编.注释可以通过在窗口中右击出现的菜单 ...