[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的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...
随机推荐
- codeforces 1151 D
SM的水题. codeforces 1151D 当时写对了,因为第一题卡了,,然后这题就没细想,原来是没开longlong. 题意:n个位置每个位置有a和b,让sum=(每个点的左面的点的数量*a+右 ...
- Hutool工具里,POST方法,body中传参的几种调用方法
接口说明: POSTMAN测试: JAVA代码: package com.provy.guard.api; import java.util.HashMap; import java.util.Map ...
- 【C++11】unoedered_map和map(部分转载)
1.结论 新版的hash_map都是unordered_map了,这里只说unordered_map和map. 运行效率:unordered_map最高,而map效率较低但提供了稳定效率和有序的序列. ...
- go语言关于值类型和引用类型
前言:关于值类型和引用类型确实是个比较绕的问题,之前在学校的时候学习C语言的时候,就感觉没有看太懂,后面看java,关于引用也是模模糊糊,这个东西也确实比较抽象,估计好多写了好几年代码的人有也有些迷惑 ...
- 四, 判断语句; 循环; 使用dict和set
1) 练习 小明身高1.75,体重80.5kg.请根据BMI公式(体重除以身高的平方)帮小明计算他的BMI指数,并根据BMI指数: 低于18.5:过轻 18.5-25:正常 25-28:过重 28- ...
- linux 服务配置
1.基本的linux 服务器防火墙配置 2.配置之前如果需要将之前的所有规则清楚 iptables -F -------清除预设表filter中的所用规则链的规则 iptables -X ---- ...
- Charles SSL
1 enable SSL 2 chls.pro/ssl to install certificate 3 General -> About -> Certificate Trust Se ...
- [原创]iFPGA-USB2.0 FT2232H USB & UART开发板使用说明
iFPGA-USB2.0 FT2232H USB & UART 开发板使用说明 基本特性: 沉金工艺: 速度达到30MB/S以上: FT2232H USB2.0免固件开发: FPGA-USB2 ...
- No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).
Java编写代码过程中遇到了一个问题,main方法中创建内部类的实例时,编译阶段出现错误,查看错误描述: No enclosing instance of type Test is accessibl ...
- ssh 连接不上报Connection closed by remote host
解决办法 (1)查看这两个文件是否有阻止cat /etc/hosts.deny cat /etc/hosts.allow (2)客户端连接数过多修改/etc/ssh/sshd_config中#MaxS ...