CF 1033 D. Divisors
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的更多相关文章
- CF 1033 C. Permutation Game
C. Permutation Game http://codeforces.com/contest/1033/problem/C 题意: 一个排列,每个位置i走到的位置j满足:a[j]>a[i] ...
- [数据结构]KMP小结
KMP小结 By Wine93 2013.9 1.学习链接: http://www.matrix67.com/blog/archives/115 2.个人小结 1.KMP在字符串中匹配中起着巨大作 ...
- CF #579 (Div. 3) C.Common Divisors
C.Common Divisors time limit per test2 seconds memory limit per test256 megabytes inputstandard inpu ...
- 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 ...
- CF刷刷水题找自信1
CF 1108A Two distinct points 题目意思:给你两个线段的起点和终点,让你给出两个不同的点,这两点分别处于两个不同的线段之中.解题思路:题目说如果存在多种可能的点,随意一组答案 ...
- 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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
随机推荐
- social psychology 10th David G. Myers
Social psychology is a science that studies the influences of our situations, with special attention ...
- 【C++ Primer | 03】字符串、向量和数组
博客链接: c++ 中 const_iterator 和 const vector<>::iterator的区别 const vector <int> ::iterator和v ...
- KnockOut -- 快速入门
简单示例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf- ...
- ubuntu多版本cuda并存与切换【两个博客链接】
https://bluesmilery.github.io/blogs/a687003b/ https://blog.csdn.net/Maple2014/article/details/785742 ...
- Faster-RCNN tensorflow 程序细节
tf-faster-rcnn github:https://github.com/endernewton/tf-faster-rcnn backbone,例如vgg,conv层不改变feature大小 ...
- windows server远程连接提示“终端服务器超出了最大允许连接”
- LVM分区无损增减
http://www.361way.com/change-lvm-size/1792.html
- day4.字符串练习题
有变量 name = “alex leNb”,完成如下操作 1. 移除name变量对应的值两边的空格,并输出处理结果 print(name.strip()) 2. 移除name变量左边的’al’并输出 ...
- BZOJ4811 [Ynoi2017]由乃的OJ 树链剖分
原文链接http://www.cnblogs.com/zhouzhendong/p/8085286.html 题目传送门 - BZOJ4811 题意概括 是BZOJ3668长在树上并加上修改和区间询问 ...
- C++实现--最大公因数和最小公倍数
一丶 最大公因数求法: 辗转相除法(也称欧几里得算法)原理: 二丶最小公倍数求法:两个整数的最小公倍数等于两整数之积除以最大公约数 C++ 代码实现 #include <iostream ...