标签:put prim long include prime init memset oid span
#include<bits/stdc++.h> using namespace std; #define ll long long #define maxn 200 int primes[maxn],m; bool vis[maxn]; void init(){ for(int i=2;i<maxn;i++){ if(!vis[i]) primes[++m]=i; for(int j=1;j<=m;j++){ if(i*primes[j]>=maxn)break; vis[i*primes[j]]=1; if(i%primes[j]==0)break; } } } int c[maxn]; void divide(int n){ memset(c,0,sizeof c); for(int i=1;i<=m && primes[i]<=n;i++){ int p=primes[i]; for(;p<=n;p*=primes[i]) c[i]+=n/p; } } int main(){ int t;cin>>t;init(); for(int tt=1;tt<=t;tt++){ int n;cin>>n; divide(n); printf("Case %d: %d = %d (%d)",tt,n,primes[1],c[1]); for(int i=2;i<=m;i++) if(c[i]) printf(" * %d (%d)",primes[i],c[i]); puts(""); } }
标签:put prim long include prime init memset oid span
原文地址:https://www.cnblogs.com/zsben991126/p/11130892.html