首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【LightOJ】1109 - False Ordering(打表)

【LightOJ】1109 - False Ordering(打表)

作者头像
FishWang
发布2025-08-27 11:42:31
发布2025-08-27 11:42:31
10000
代码可运行
举报
运行总次数:0
代码可运行

点击打开题目

1109 - False Ordering

PDF (English)

Statistics

Forum

Time Limit: 1 second(s)

Memory Limit: 32 MB

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

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

打一个因子表,sort 后就好了。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(a,b) memset(a,b,sizeof(a))
#define LL long long
#define PI acos(-1.0)
struct node
{
	int n,m;
}a[1005];
bool cmp(node x,node y)
{
	if (x.m == y.m)
		return x.n > y.n;
	return x.m < y.m;
}
int main()
{
	int u;
	int n;
	int Case = 1;
	for (int i = 1 ; i <= 1000 ; i++)
	{
		a[i].n = i;
		a[i].m = 1;
	}
	for (int i = 2 ; i <= 1000 ; i++)
	{
		for (int j = i ; j <= 1000 ; j += i)
			a[j].m++;
	}
	sort(a+1,a+1001,cmp);
	scanf ("%d",&u);
	while (u--)
	{
		scanf ("%d",&n);
		printf ("Case %d: ",Case++);
		printf ("%d\n",a[n].n);
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Input
  • Output
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档