数学知识

试除法:

//试除法 
inline bool check(int x)
{
    if(x<=2) return false;
    for(register int i=2;i<=sqrt(x);++i)
        if(x%i==0) return false;
    return true;    
} 
//E筛法
for(register int i=2;i<=n;++i)
{
    if(vis[i]) continue;vis[i]=1;
    for(int j=i;j*i<=n;++j) vis[i*j]=1;
} 
//质因数分解
void divide(int n)
{
    m=0;
    for(register int i=2;i<=sqrt(n);++i)
    {
        if(n%i==0) 
        {
            p[++m]=i;c[m]=0;
            while(n%i==0) n/=i,c[m]++; 
        }
    }
    if(n>1) p[++m]=n,c[m]=1;
    for(register int i=1;i<=m;++i) cout<<p[i]<<'^'<<c[i];
} 
posted @ 2020-01-01 21:29  逆天峰  阅读(147)  评论(0编辑  收藏  举报
作者:逆天峰
出处:https://www.cnblogs.com/gcfer//