HDU 4344

其实不过是大整数分解。。。

注意两点:注意L 不能==N

但是,N却可以是素数。。。囧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdio>
#define LL __int64
#define MAX 1LL<<61
#define Times 8
#define N 501
#define C 101
using namespace std;
LL cop[N];
int ct;
 
bool cmp(LL a,LL b){
    if(a<b) return true;
    return false;
}
 
LL gcd(LL a,LL b){
    return b==0?a:gcd(b,a%b);
}
 
LL random(LL n){
    return (LL)((double)rand()/RAND_MAX*n+0.5);
}
 
LL multi(LL a,LL b,LL m){   //a*b%m
    LL ret=0;
    while(b){
        if(b&1)
        ret=(ret+a)%m;
        b>>=1;
        a=(a<<1)%m;
    }
    return ret;
}
 
LL quick(LL a,LL b,LL m){
    LL ans=1;
    a%=m;
    while(b){
        if(b&1){
            ans=multi(ans,a,m);
            b--;
        }
        b/=2;
        a=multi(a,a,m);
    }
    return ans;
}
 
bool Witness(LL a,LL n){
    LL m=n-1;
    int j=0;
    while(!(m&1)){
        j++;
        m>>=1;
    }
    LL x=quick(a,m,n);
    if(x==1||x==n-1)
    return false;
    while(j--){
        x=multi(x,x,n);
        if(x==n-1)
        return false;
    }
    return true;
}
 
bool Miller_Rabin(LL n){
    if(n<2) return false;
    if(n==2) return true;
    if(!(n&1)) return false;
    for(int i=1;i<=Times;i++){
        LL a=random(n-2)+1;
        if(Witness(a,n)) return false;
    }
    return true;
}
 
LL Pollard_Rho(LL n,int c){
    LL x,y,d,i=1,k=2;
    x=random(n-1)+1;
    y=x;
    while(true){
        i++;
        x=(multi(x,x,n)+c)%n;
        d=gcd(y-x,n);
        if(d>1&&d<n){
            return d;
        }
        if(y==x) return n;
        if(i==k){
            y=x;
            k=k<<1;
        }
    }
}
 
void find(LL n,int k){
    if(n==1) return ;
    if(Miller_Rabin(n)){
        cop[++ct]=n;
        return ;
    }
    LL p=n;
    while(p>=n)
    p=Pollard_Rho(p,k--);
    find(p,k);
    find(n/p,k);
}
 
int main(){
    int T;
    LL n;
    scanf("%d",&T);
    while(T--){
        scanf("%I64d",&n);
        ct=0;
        find(n,C);
        sort(cop+1,cop+1+ct,cmp);
        if(ct==1){
            printf("1 1\n");
            continue;
        }
        LL cnt=0;LL tmp=0; LL ans=0;
        cop[0]=1;
        cop[++ct]=1;
        for(int i=1;i<=ct;i++){
            if(cop[i]!=cop[i-1]){
                ans+=tmp;
                tmp=cop[i];
                cnt++;
            }
            else{
                tmp*=cop[i];
            }
        }
        if(ans==n)
        ans/=cop[1];
        printf("%I64d %I64d\n",cnt-1,ans);
    }
    return 0;
}

  

posted @   chenjunjie1994  阅读(194)  评论(0编辑  收藏  举报
编辑推荐:
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
阅读排行:
· 为DeepSeek添加本地知识库
· .NET程序员AI开发基座:Microsoft.Extensions.AI
· 精选4款基于.NET开源、功能强大的通讯调试工具
· 数据不出内网:基于Ollama+OneAPI构建企业专属DeepSeek智能中台
· 大模型工具KTransformer的安装
点击右上角即可分享
微信分享提示