PDF (English) | Statistics | Forum |
Time Limit: 1 second(s) | Memory Limit: 32 MB |
We define b is a Divisor of a number a if ais divisible by b. So, the divisors of 12are 1, 2, 3, 4, 6, 12. So, 12 has 6 divisors.
Now you have to order all theintegers from 1 to 1000. x will come before y if
1) numberof divisors of x is less than number of divisors ofy
2) numberof divisors of x is equal to number of divisors ofy and x> y.
Input starts with an integer T (≤ 1005),denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤1000).
For each case, print the case number and the nthnumber after ordering.
Sample Input |
Output for Sample Input |
5 1 2 3 4 1000 |
Case 1: 1 Case 2: 997 Case 3: 991 Case 4: 983 Case 5: 840 |
ac代码:
#include<stdio.h> #include<math.h> #include<string.h> #include<stack> #include<set> #include<queue> #include<vector> #include<iostream> #include<algorithm> #define MAXN 1010100 #define LL long long #define ll __int64 #define INF 0x7fffffff #define mem(x) memset(x,0,sizeof(x)) #define PI acos(-1) #define eps 1e-10 using namespace std; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;} int lcm(int a,int b){return a/gcd(a,b)*b;} LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;} //head struct s { int num; int k; }ans[1010]; bool cmp(s a,s b) { if(a.k==b.k) return a.num>b.num; return a.k<b.k; } void db() { int i,j; for(i=1;i<=1000;i++) { ans[i].num=i; ans[i].k=1; int x=i; int n=i; for(j=2;j<=sqrt(n);j++) { if(x%j==0) { int cnt=0; while(x%j==0) { cnt++; x/=j; } ans[i].k=ans[i].k*(cnt+1); } } if(x>1) ans[i].k*=2; } sort(ans,ans+1001,cmp); } int main() { db(); int t,i,j; int n,k; int cas=0; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("Case %d: ",++cas); printf("%d\n",ans[n].num); } return 0; }