题目链接: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]的更多相关文章

  1. Lyft Level 5 Challenge 2018 - Elimination Round

    A. King Escape 签. #include <bits/stdc++.h> using namespace std; ], y[]; int f1(int X, int Y) { ...

  2. Lyft Level 5 Challenge 2018 - Elimination Round翻车记

    打猝死场感觉非常作死. A:判一下起点和终点是否在其两侧即可. #include<iostream> #include<cstdio> #include<cmath> ...

  3. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  4. 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 ...

  5. 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)\), 现 ...

  6. 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的矩阵中的左下角,放置一个车(车可以移动到同一行或同一列),放置一些墙,竖的占据 ...

  7. 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, ...

  8. 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, ...

  9. Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记

    夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...

随机推荐

  1. 【转】web.xml中的contextConfigLocation在spring中的作用

    一.spring中如何使用多个xml配置文件 1.在web.xml中定义contextConfigLocation参数,Spring会使用这个参数去加载所有逗号分隔的xml文件,如果没有这个参数,sp ...

  2. Filebeat 启动关闭流程

    启动阶段: instance/beat.go #打印home路径.配置路径.数据路径和日志路径 seccomp #Syscall filter检查 instance/beat.go #beat inf ...

  3. 泛型约束new()的使用

    下面泛型约束代码,where字句后面有new()约束,T类型必须有公有的无参的构造函数. private T InternalCreate<T>() where T : IObjectWi ...

  4. 创建Git 仓库及 克隆、拉取、和推送操作

    打开网址:     https://github.com/ 登录上自己创建的 Git账号   一. 创建Git 仓库          start  a project--->     输入仓库 ...

  5. UiAutomator2.0 - 与AccessibilityService的关联

    目录 一.Android中的 Accessibility 二.UiAutomator2.0 与 AccessibilityService 三.验证与 AccessibilityService的关联 A ...

  6. linux工具-journalctl查询日志

    有时候,当linux服务启动失败的时候,系统会提示我们使用journalctl -xe命令来查询详细信息,定位服务不能启动的原因. journalctl 用来查询 systemd-journald 服 ...

  7. docker bulid命令

    使用当前目录的 Dockerfile 创建镜像,标签为 runoob/ubuntu:v1. docker build -t runoob/ubuntu:v1 . 使用URL github.com/cr ...

  8. 《剑指offer》两个链表中的第一个公共节点

    本题来自<剑指offer> 反转链表 题目: 思路: C++ Code: Python Code: 总结:

  9. python3学习笔记之十七

    1.  网站本质:通过socket建立连接. 服务端(网站) 1.  先启动并监听:80端口 4.  获取请求信息 请求头 请求体 5.  处理请求 响应内容: 响应头:\r\n\r\n响应体     ...

  10. node 和 npm 常用命令

    npm node 简述 快速入门 安装npm和管理npm版本 npm安装 更新npm npm -v npm install npm@latest -g npm install npm@next -g ...