您的位置:首页 > 其它

CodeForcesGym 100753F Divisions

2015-10-05 19:34 399 查看

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)

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100001;
LL mul(LL a,LL b,LL mod) {
if(!a) return 0;
return ((a&1)*b%mod + (mul(a>>1,b,mod)<<1)%mod)%mod;
}
LL quickPow(LL a,LL d,LL n) {
LL ret = 1;
while(d) {
if(d&1) ret = mul(ret,a,n);
d >>= 1;
a = mul(a,a,n);
}
return ret;
}
bool check(LL a,LL d,LL n) {
if(n == a) return true;
while(~d&1) d >>= 1;
LL t = quickPow(a,d,n);
while(d < n-1 && t != 1 && t != n-1) {
t = mul(t,t,n);
d <<= 1;
}
return (d&1) || t == n-1;
}
bool isP(LL n) {
if(n == 2) return true;
if(n < 2 || 0 == (n&1)) return false;
static int p[5] = {2,3,7,61,24251};
for(int i = 0; i < 5; ++i)
if(!check(p[i],n-1,n)) return false;
return true;
}
LL gcd(LL a,LL b) {
if(a < 0) return gcd(-a,b);//特别注意,没这个TLE
return b?gcd(b,a%b):a;
}
LL Pollard_rho(LL n,LL c) {
LL i = 1,k = 2,x = rand()%n,y = x;
while(true) {
x = (mul(x,x,n) + c)%n;
LL d = gcd(y - x,n);
if(d != 1 && d != n) return d;
if(y == x) return n;
if(++i == k) {
y = x;
k <<= 1;
}
}
}
LL Fac[maxn],tot;
void factorization(LL n) {
if(isP(n)) {
Fac[tot++] = n;
return;
}
LL p = n;
while(p >= n) p = Pollard_rho(p,rand()%(n-1)+1);
factorization(p);
factorization(n/p);
}
unordered_map<LL,LL>ump;
int main() {
LL x;
srand(time(0));
while(~scanf("%I64d",&x)){
tot = 0;
if(x == 1) {
puts("1");
continue;
}
if(isP(x)){
puts("2");
continue;
}
factorization(x);
ump.clear();
for(int i = 0; i < tot; ++i)
ump[Fac[i]]++;
unsigned long long  ret = 1;
for(auto &it:ump) ret *= (it.second + 1);
printf("%I64u\n",ret);
}
return 0;
}
/*
999999999999999989
100000007700000049
*/


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: