ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2019.2.14 t1 最大公约数

2019-02-14 21:53:37  阅读:192  来源: 互联网

标签:ch 14 res LL 2019.2 t1 10000000 long include


代码:

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <cmath>
 6 #include <cctype>
 7 #include <vector>
 8 using namespace std;
 9 
10 #define LL long long
11 #define res register long long
12 inline LL read()
13 {
14     LL x(0),f(1); char ch;
15     while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
16     while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
17     return f*x;
18 }
19 LL s[10000000],tot;
20 LL b[10000000],cnt;
21 inline void pre_work(LL n)
22 {
23     //质因数 
24     LL tmp=n;
25     for(res i=2 ; i*i<=n ; i++)
26     {
27         if(n%i==0) s[++tot]=i;
28         while(n%i==0) n/=i;
29     }
30     if(n>1) s[++tot]=n;
31     //约数 
32     for(res i=1 ; i*i<=tmp ; i++)
33         if(tmp%i==0)
34         {
35             b[++cnt]=i;
36             if(i!=tmp/i) b[++cnt]=tmp/i;
37         }
38 }
39 
40 LL phi(LL n)
41 {
42     LL ans=n;
43     for(res i=1 ; i<=tot ; i++)
44     {
45         if(n%s[i]==0) 
46             ans=ans/s[i]*(s[i]-1);
47     }
48     return ans;
49 }
50 
51 int main()
52 {
53 //    freopen("gcd.in","r",stdin);
54 //    freopen("gcd.out","w",stdout);
55     LL n;
56     n=read();
57     pre_work(n);
58     sort(b+1,b+cnt+1);
59     for(res i=1 ; i<=cnt ; i++)
60     {
61         cout<<b[i]<<" ";
62         cout<<phi(n/b[i])<<endl;
63     }
64     return 0;
65 }
View Code

 

标签:ch,14,res,LL,2019.2,t1,10000000,long,include
来源: https://www.cnblogs.com/wmq12138/p/10380890.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有