[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的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...
随机推荐
- 20175315Mycp
MyCP(课下作业,必做) 要求 编写MyCP.java 实现类似Linux下cp XXX1 XXX2的功能,要求MyCP支持两个参数: java MyCP -tx XXX1.txt XXX2.bin ...
- 使用scrapy爬虫,爬取今日头条搜索吉林疫苗新闻(scrapy+selenium+PhantomJS)
这一阵子吉林疫苗案,备受大家关注,索性使用爬虫来爬取今日头条搜索吉林疫苗的新闻 依然使用三件套(scrapy+selenium+PhantomJS)来爬取新闻 以下是搜索页面,得到吉林疫苗的搜索信息, ...
- 【Python】Flask中@wraps的使用
先说总结,白话来讲,@wraps相当于是装饰器的装饰器. python内置的方法使用解释,看起很复杂的样子┓( ´∀` )┏ def wraps(wrapped, assigned = WRAPPER ...
- 【python】【logging】python日志模块logging常用功能
logging模块:应用程序的灵活事件日志系统,可以打印并自定义日志内容 logging.getLogger 创建一个log对象 >>> log1=logging.getLogger ...
- CRMEB系统开发文档
CRMEB系统开发文档 https://gitee.com/ZhongBangKeJi/CRMEB hibernate:学习文档https://blog.csdn.net/u013087513/art ...
- docker简单介绍----存储
docker容器 中使用Volumes来实现数据的持久性,因为容器的删除会丢失数据,而关闭或者重启容器不会丢失数据 docker run -v即可使用Volumes 1.docker-managed ...
- onscroll 元素滚动事件
阻止事件冒泡 event.stopPropagation(); children():查找合集里面的第一级子元素.(仅儿子辈,这里可以理解为就是父亲-儿子的关) children只查找第一级的子节点 ...
- ThinkPHP 2053错误
这个报错是调用存储过程的时候产生的,用的是5.1的代码是根据官方文档写的,我怀疑5.0也有这个问题.去官方查了一下发现不少人有这个问题,但是官方都没有回应过,只能自己动手一步步调了. $center ...
- web.xml中DispatcherServlet拦截器的配置详情
<welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file& ...
- CAS5.3.0安装部署
部署环境:JDK1.8.x maven-3.5.2 tomcat-8.x.x 1.下载地址 https://github.com/apereo/cas-overlay-template/tree/5. ...