Divisions

Time Limit: 2000ms
Memory Limit: 262144KB

This problem will be judged on  CodeForcesGym. Original ID: 100753F
64-bit integer IO format: %I64d      Java class name: (Any)

解题:大数质因子分解

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn = 100001;
 5 LL mul(LL a,LL b,LL mod) {
 6     if(!a) return 0;
 7     return ((a&1)*b%mod + (mul(a>>1,b,mod)<<1)%mod)%mod;
 8 }
 9 LL quickPow(LL a,LL d,LL n) {
10     LL ret = 1;
11     while(d) {
12         if(d&1) ret = mul(ret,a,n);
13         d >>= 1;
14         a = mul(a,a,n);
15     }
16     return ret;
17 }
18 bool check(LL a,LL d,LL n) {
19     if(n == a) return true;
20     while(~d&1) d >>= 1;
21     LL t = quickPow(a,d,n);
22     while(d < n-1 && t != 1 && t != n-1) {
23         t = mul(t,t,n);
24         d <<= 1;
25     }
26     return (d&1) || t == n-1;
27 }
28 bool isP(LL n) {
29     if(n == 2) return true;
30     if(n < 2 || 0 == (n&1)) return false;
31     static int p[5] = {2,3,7,61,24251};
32     for(int i = 0; i < 5; ++i)
33         if(!check(p[i],n-1,n)) return false;
34     return true;
35 }
36 LL gcd(LL a,LL b) {
37     if(a < 0) return gcd(-a,b);//特别注意,没这个TLE
38     return b?gcd(b,a%b):a;
39 }
40 LL Pollard_rho(LL n,LL c) {
41     LL i = 1,k = 2,x = rand()%n,y = x;
42     while(true) {
43         x = (mul(x,x,n) + c)%n;
44         LL d = gcd(y - x,n);
45         if(d != 1 && d != n) return d;
46         if(y == x) return n;
47         if(++i == k) {
48             y = x;
49             k <<= 1;
50         }
51     }
52 }
53 LL Fac[maxn],tot;
54 void factorization(LL n) {
55     if(isP(n)) {
56         Fac[tot++] = n;
57         return;
58     }
59     LL p = n;
60     while(p >= n) p = Pollard_rho(p,rand()%(n-1)+1);
61     factorization(p);
62     factorization(n/p);
63 }
64 unordered_map<LL,LL>ump;
65 int main() {
66     LL x;
67     srand(time(0));
68     while(~scanf("%I64d",&x)){
69         tot = 0;
70         if(x == 1) {
71             puts("1");
72             continue;
73         }
74         if(isP(x)){
75             puts("2");
76             continue;
77         }
78         factorization(x);
79         ump.clear();
80         for(int i = 0; i < tot; ++i)
81             ump[Fac[i]]++;
82         unsigned long long  ret = 1;
83         for(auto &it:ump) ret *= (it.second + 1);
84         printf("%I64u\n",ret);
85     }
86     return 0;
87 }
88 /*
89 999999999999999989
90 100000007700000049
91 */

View Code

转载于:https://www.cnblogs.com/crackpotisback/p/4856163.html

CodeForcesGym 100753F Divisions相关推荐

  1. 素数一套:Miller-Rabin 素性检验算法Pollard-Rho算法线性筛——Upside down primesDivisions

    部分目录 Solved 94 / 304 K Gym 100753K Upside down primes 高效判断素数 快速幂取模 继续 Miller-Rabin 素性检验算法 Unsolved 6 ...

  2. CF-Edu101-D-Ceil Divisions(构造)

    CF-Edu101-D-Ceil Divisions(构造) 题意: 给定 n n n 个数,从 1 1 1 到 n n n .现在有一种操作,每一次可以选择两个数 x , y ( x ≠ y ) x ...

  3. D. Ceil Divisions

    D. Ceil Divisions 题意: a[i] = i 一共有n个数字, 操作 最多操作n+5次,让数组a 变成一个2 和剩下全部是1 题解:首先我们如果要最后单独处理n的话一定会大于n+5次的 ...

  4. CodeForces - 1469D - Ceil Divisions (思维+数学)

    Ceil Divisions 题意 对于一个大小为 n n n 的排列 在一次操作中可以选择两个数 a x a_x ax​ 和 a y a_y ay​ ( x ≠ y ) (x≠y) (x​=y) ...

  5. Codeforce D. Ceil Divisions (构造+思维)

    题目链接 题意: 给你一个长度为 \(n\) 的序列 \(a\) 满足 \(a_i=i\) 你每次可以进行一次如下操作: 选择两个数 \(a_x,a_y\),将 \(a_x\) 修改为 \(\lcei ...

  6. CodeForcesGym 100753B Bounty Hunter II 二分图最小路径覆盖

    关键在建图 题解:http://www.cnblogs.com/crackpotisback/p/4856159.html 学习:http://www.cnblogs.com/jackiesteed/ ...

  7. Educational Codeforces Round 101 (Rated for Div. 2) D. Ceil Divisions 思维 + 根号数

    传送门 题意: 给一个数组ai=ia_i=iai​=i,每次可以进行操作ax=⌈axay⌉a_x=\left \lceil \frac{a_x}{a_y} \right \rceilax​=⌈ay​a ...

  8. codeforces1469D Ceil Divisions(构造题、规律题)

    传送门 题解:其实就是发现规律来构造的题目,题目要 n + 5 n+5 n+5步构造完成,那么必然有很多操作是第 i i i个数除以第 i + 1 i+1 i+1个数,可以发现一个大数要想降下来,最少 ...

  9. Ceil Divisions(递归,黄金分割应用)

    链接 You have an array a 1 , a 2 , - , a n a_1,a_2,-,a_n a1​,a2​,-,an​ where a i = i a_i=i ai​=i. In o ...

最新文章

  1. android帧动画实现方法之一
  2. LevelDb系列之简介
  3. python使用statsmodels包中的tsaplots函数可视化时间序列数据所有滞后位置个数(级别)的自相关性(plot the autocorrelation function)
  4. LeetCode 45跳跃游戏46全排列
  5. Redis系列(四)-低成本高可用方案设计
  6. Python函数名的第一类对象及使用
  7. python判断几个数最大最小_python 找出list中最大或者最小几个数的索引方法
  8. 李连杰年度巨作霍元甲主题曲:周杰伦唱
  9. 删除操作记录_微信消费记录能删吗?专家告诉你这样做百分百彻底删除!
  10. 网络爬虫随记:2018-03-12启(refreshing)
  11. 阿里云服务器安全组宝塔端口8888开放教程
  12. 贵阳市交通大数据中心
  13. SpaceSniffer(磁盘大小扫描分析) 彻底解决C盘爆满问题 清理C盘必备软件
  14. Windows 7笔记本创建wifi热点供手机上网教程
  15. nltk词性标注的涵义
  16. java数据结构与算法基础(二)-排序
  17. MySQL编程:将查询到的字段赋值给变量
  18. [HOW TO]-oppo手机安装google play
  19. sh shell实现自动杀死cpu占用最高的pid,同时当cpu超过95%自动重启apache
  20. 知到/智慧树——英语听说:实境主题与技能(参考答案)

热门文章

  1. 树莓派驱动数码管c 语言,0023 树莓派电脑控制单位数码管显示数字
  2. 网络连接的常见问题和解决方法
  3. 高级车道线查找项目的相机标定
  4. Codeforences Educational Round10 C. Foe Pairs
  5. python画名字七十周年快乐用英语怎么说_四周年快乐用英语怎么说?
  6. 雷神之锤Live Review and Rant-为什么这很有趣?
  7. 奔三了,悲催的IT职业生涯仍然没找到方向
  8. emeditor正则表达式_EmEditor 正则表达式使用实例教程
  9. 大学计算机基础操作心得体会,大学计算机基础心得体会
  10. P2P网络——Kademila算法