算法训练——素因子去重
//素因子去重 #include<stdio.h> int num[4000000] = {0}; int main(){ long long n,ans; scanf("%d",&n); if(n==2){ printf("%d",n); return 0; } for(int k=2;k<=n;){ //从最小的质因数开始 if(k==n){ num[k] = 1; break; } else if(n%k == 0){ num[k] = 1; n = n/k; } else k++; } for(int i=2;i<=n;i++){ if(num[i] == 1) ans *= i; } printf("%d",ans); return 0; }
相关推荐
湾区人工智能 2020-11-20
Pokemogo 2020-11-16
baijingjing 2020-11-16
baijingjing 2020-11-15
Site 2020-11-07
lwnylslwnyls 2020-11-06
justaipanda 2020-11-05
MachineIntellect 2020-11-02
xueyuediana 2020-10-30
GeraldJones 2020-10-30
Tips 2020-10-29
baijingjing 2020-10-28
baijingjing 2020-10-27
硕鼠 2020-10-26
playoffs 2020-10-26
scuyxi 2020-10-25
playoffs 2020-10-25
yise001 2020-10-23