就是暴力嘛。。。很水的一个题。。。
不好意思交都。。。
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cmath> #define MOD 2018 #define LL long long #define ULL unsigned long long #define Pair pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define _ ios_base::sync_with_stdio(0),cin.tie(0) //freopen("1.txt", "r", stdin); using namespace std; const int maxn = 10010, INF = 0x7fffffff; int primes[maxn], base[maxn], mi[maxn]; int vis[maxn]; int ans = 0; set<int> s; void init() { mem(vis, 0); for(int i=2; i<maxn; i++) { if(vis[i]) continue; primes[ans++] = i; for(LL j=(LL)i*i; j<maxn; j+=i) vis[j] = 1; } } int main() { init(); int T, kase = 0; scanf("%d",&T); while(T--) { s.clear(); mem(base, 0); int n; scanf("%d",&n); for(int i=2; i<=n; i++) { int temp = i; for(int j=0; j<ans && primes[j] * primes[j] <= temp; j++) { while(temp % primes[j] == 0) { temp /= primes[j]; base[primes[j]]++; } if(base[primes[j]] > 0) { s.insert(primes[j]); } } if(temp > 1) { base[temp]++; s.insert(temp); } } printf("Case %d: %d = ",++kase, n); int cnt = 0; for(set<int>::iterator it=s.begin(); it!=s.end(); it++) { if(cnt == 0) printf("%d (%d)",*it, base[*it]); else printf(" * %d (%d)",*it, base[*it]); cnt++; } printf(" "); } return 0; }