False Ordering LightOJ - 1109(暴力。。唉,。又是一个水题。。)
We define b is a Divisor of a number a if a is divisible by b. So, the divisors of 12 are 1, 2, 3, 4, 6, 12. So, 12 has 6 divisors.
Now you have to order all the integers from 1 to 1000. x will come before y if
1) number of divisors of x is less than number of divisors of y
2) number of divisors of x is equal to number of divisors of y and x > y.
Input
Input starts with an integer T (≤ 1005), denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤ 1000).
Output
For each case, print the case number and the nth number after ordering.
Sample Input
5
1
2
3
4
1000
Sample Output
Case 1: 1
Case 2: 997
Case 3: 991
Case 4: 983
Case 5: 840
直接分解质因子 暴力就好了。。。
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cmath> #define rap(a, n) for(int i=1; i<=n; i++) #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], vis[maxn], sum[maxn]; int ans; struct node { int id, xi; }Node[maxn]; 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; } } bool cmp(node a, node b) { if(a.xi == b.xi) return a.id > b.id; return a.xi < b.xi; } int main() { ans = 0; init(); rap(1, 1000) { Node[i].id = i; Node[i].xi = 1; int temp = i; for(int j=0; j<ans && primes[j] * primes[j] <= temp; j++) { int cnt2 = 0; while(temp % primes[j] == 0) { temp /= primes[j]; cnt2++; } if(cnt2 > 0) Node[i].xi *= (cnt2+1); } if(temp > 1) Node[i].xi *= 2; } sort(Node+1, Node+1+1000, cmp); int T, kase = 0; cin>> T; while(T--) { int n; cin>> n; printf("Case %d: %d\n",++kase, Node[n].id); } return 0; }
自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。