D. Divisors

http://codeforces.com/contest/1033/problem/D

题意:

  给n个(n<=500)个数,($a_i <= 2 \times 10 ^ {18}$),每个数的因数个数在[3,5]内。$a = \prod\limits_{i=1}^na_i$,求a的因数个数。

分析:

  首先有一个结论:一个数x的质因数分解后为:$x = p_1^{a_1}p_2^{a_2}...p_k^{a_k}$ 那么它的因数个数就是 $(a_1 + 1) \times (a_2 + 1) \times ... \times (a_k + 1)$。

  于是这道题就可以求出每个质因数的个数,然后将指数+1相乘即可。

  但是$a_i$太大了,无法直接求质因数。

  因为每个数的因数个数在[3,5]范围内,所以根据上面的结论,可以知道每个数的质因数分解只有四种形式:$pq, p^2, p^3,p^4$。后三种直接二分就能算出其质因数,用map记录每个质因数的指数。

  对于第一种,直接求质因数是不可能的了,考虑能否不求质因数,而计算答案。首先对于所有数二分,如果不能分成后三种,那么将其记录到b数组中。b中的一个数拆成第一种形式后,p和q,在map都没出现过,那么我们可以知道它的贡献就是(2*2)了(不考虑后面的)。如果p和q中有一个出现过了,我们必须要合并他们的幂。

  如何合并幂:枚举b[i],枚举a数组中的所有数,求gcd,如果1<gcd<b[i],那么可以说明b[i]和a[j]分解后的都有gcd,(b[i]=pq,gcd=p或者q)。

  对于剩下的数,每一个分解后的质数都是还未出现过,直接计算答案。

代码:

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cctype>
#include<set>
#include<vector>
#include<queue>
#include<map>
#define fi(s) freopen(s,"r",stdin);
#define fo(s) freopen(s,"w",stdout);
using namespace std;
typedef long long LL; inline LL read() {
LL x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = ;
const int mod = ;
const LL INF = 9e18; LL a[N], b[N], c[N];
map<LL,int> f;
LL Sqrt(LL x,int k) {
LL l = , r; // 虽然现在的l,r在int范围内,但是也要开longlong!!!!!
if (k == ) r = ;
if (k == ) r = ;
if (k == ) r = ;
while (l <= r) {
LL mid = (l + r) >> ;
LL t = ;
for (int i=; i<=k; ++i) t = 1ll * t * mid;
if (t == x) return mid;
else if (t > x) r = mid - ;
else l = mid + ;
}
return -;
}
LL gcd(LL a,LL b) {
return b == ? a : gcd(b, a % b);
}
int main() {
int n = read();
for (int i=; i<=n; ++i) a[i] = read(); for (int i=; i<=n; ++i) {
bool flag = ;
for (int k=; k>=; --k) { // 从大到小!!!
LL p = Sqrt(a[i], k);
if (p != -) { f[p] += k; flag = ; break; }
}
if (!flag) b[i] = a[i];
}
for (int i=; i<=n; ++i) {
if (!b[i]) continue;
bool flag = ;
for (int j=; j<=n; ++j) {
if (i == j) continue;
LL d = gcd(b[i], a[j]);
if (d != && d != b[i]) {
flag = ; f[d] ++; f[b[i] / d] ++; break;
}
}
if (!flag) c[i] = b[i];
}
LL ans = ;
for (int i=; i<=n; ++i) {
if (!c[i]) continue;
LL cnt = ;
for (int j=; j<=n; ++j)
if (i != j && c[i] == c[j]) cnt ++, c[j] = ;
cnt = cnt * cnt % mod;
ans = ans * cnt % mod;
}
map<LL,int> :: iterator it;
for (it=f.begin(); it!=f.end(); it++)
ans = (ans * (it->second + )) % mod;
// for (auto p: f) ans = (ans * (p.second + 1)) % mod;
cout << ans;
fflush(stdout);
return ;
}

CF 1033 D. Divisors的更多相关文章

  1. CF 1033 C. Permutation Game

    C. Permutation Game http://codeforces.com/contest/1033/problem/C 题意: 一个排列,每个位置i走到的位置j满足:a[j]>a[i] ...

  2. [数据结构]KMP小结

    KMP小结   By Wine93 2013.9 1.学习链接: http://www.matrix67.com/blog/archives/115 2.个人小结 1.KMP在字符串中匹配中起着巨大作 ...

  3. CF #579 (Div. 3) C.Common Divisors

    C.Common Divisors time limit per test2 seconds memory limit per test256 megabytes inputstandard inpu ...

  4. CF A. Xenia and Divisors

    题目大意: n(为三的倍数)个数的一个序列(每个数均不大于7),找出a,b,c a能被b整除,b能被c整除,序列中的每个数都被用到. 1 2 3 4 5 6 7 只有 1 2 4 1 2 6 1 3 ...

  5. CF刷刷水题找自信1

    CF 1108A Two distinct points 题目意思:给你两个线段的起点和终点,让你给出两个不同的点,这两点分别处于两个不同的线段之中.解题思路:题目说如果存在多种可能的点,随意一组答案 ...

  6. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  9. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

随机推荐

  1. https://www.cnblogs.com/zoro-robin/p/6110188.html

    https://www.cnblogs.com/zoro-robin/p/6110188.html https://blog.csdn.net/kongxx/article/details/65435 ...

  2. Java判断不为空的工具类总结

    1.Java判断是否为空的工具类,可以直接使用.包含,String字符串,数组,集合等等. package com.bie.util; import java.util.Collection; imp ...

  3. Ansible playbook 部署Openresty

    - hosts: all tasks: - name: copy package copy: src=/usr/local/openresty-1.13.6.1.tar.gz dest=/usr/lo ...

  4. 移动端根据不同DPR加载大小不同的图片

    1.首先创建mixin.styl文件代码如下: bg-image($url) // 创建bg-image($url)函数 background-image: url($url + "@2x. ...

  5. python_异常处理_断言

    一.Python标准异常 常用异常 Exception 常规错误的基类 AttributeError 试图访问一个对象没有的属性 IOError 输入/ 输出异常,基本上是无法打开文件 ImportE ...

  6. 2018牛客网暑假ACM多校训练赛(第八场)H Playing games 博弈 FWT

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round8-H.html 题目传送门 - https://www.no ...

  7. 044 hive与mysql两种数据源之间的join

    这篇文章是基于上一篇文章的续集 一:需求 1.图形表示 二:程序 1.程序. package com.scala.it import java.util.Properties import org.a ...

  8. JavaEE 之 log4j

    1.log4j a.概念:一个非常优秀的开源日志记录工具 b.配置: ①src同目录下建立log4j.properties文件,书写: log4j.rootLogger=debug,appender1 ...

  9. 003.Ansible基础使用

    一 Ansible命令用法 Ansible命令行执行方式有:Ad-Hoc.Ansible-playbook两种,Web方式其官方提供付费产品Tower.Ad-Hoc主要用于临时命令的执行,Ansibl ...

  10. 001.Linux开机启动过程

    相关Linux启动过程解析,此作为通用启动参考: