LightOJ 1109 - False Ordering (因式分解)

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

题目大意:

  题目说的是,给你[1,1000]里面的数字,让你按照如下的两条规则来排序,

  1.如果x的因子的个数大于y的因子的个数,那么y排在x的前面。

  2.如果x的因子的个数等于y的因子的个数,且x>y,那么x排在y的前面。

解题思路:

  直接打表,然后按照以上两条规则来sort就可以了。

代码:

 1 # include<cstdio>
 2 # include<iostream>
 3 # include<algorithm>
 4
 5 using namespace std;
 6
 7 # define MAX 1234
 8
 9 int a[MAX];
10
11 struct node
12 {
13     int val;
14     int id;
15 }num[MAX];
16
17
18 int cmp ( const struct node & x,const struct node & y )
19 {
20     if ( x.val==y.val )
21     {
22         return x.id > y.id;
23     }
24     return x.val < y.val;
25 }
26
27
28 void init()
29 {
30     for ( int i = 1;i <= 1000;i++ )
31     {
32         num[i].id = i;
33         for ( int j = 1;j <= i;j++ )
34         {
35             if ( i%j == 0 )
36             {
37                 num[i].val++;
38             }
39         }
40     }
41 }
42
43
44
45 int main(void)
46 {
47     init();
48     sort(num+1,num+1001,cmp);
49     int icase = 1;
50     int t;scanf("%d",&t);
51     while ( t-- )
52     {
53         int n;scanf("%d",&n);
54         printf("Case %d: ",icase++);
55         printf("%d\n",num[n].id);
56
57     }
58
59
60     return 0;
61 }

代码:

时间: 2024-08-29 13:07:36

LightOJ 1109 - False Ordering (因式分解)的相关文章

LightOJ 1109 -1354 - IP Checking(字符串的处理)

题目大意: 这题的意思就是说,给两个字符串,一个字符串中的数字是用10进制表示的,一个字符串的数字是用2进制表示的,看看十进制和二进制是否对应. 解题思路: 处理在'.'上.... 代码: 1 # include<cstdio> 2 # include<iostream> 3 # include<cstring> 4 # include<cmath> 5 6 using namespace std; 7 8 # define MAX 50 9 10 char

lightoj Beginners Problems

很多以前写的丑代码 1000 - Greetings from LightOJ #include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&

LightOJ Beginners Problems 部分题解

相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's Fantabulous Birthday. 找规律题,左边列是1 3平方 5平方......下边行是1 2平方 4平方......,找到当前数被包夹的位置,然后处理一下位置关系,注意奇偶. 1010 Kinghts in Chessboard. 规律题,对于m,n大于2的情况下,使用交叉放置的方法

light oj Beginners Problems

很多以前写的丑代码 1000 - Greetings from LightOJ #include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&

DataTables.js插入数据的两种方式

一:采用数组的方式插入值 var tableData = []; var i = 0; var idxTable = 1; $.each(data, function (i, d) { tableData.push([idxTable, d.stcd, d.stnm, d.ddz, d.ddcp, d.ckflz,d.normz,d.ttcp,d.actcp,d.z,d.w,d.inq,d.oz,d.outq,d.adjw,"","","查看"]

吉特仓储管系统(开源WMS)--Web在线报表以及打印模板分享

很早之前就想写这篇文章与大家分享一下自己在吉特仓储管理系统中开发打印和报表的功能,在GitHub(https://github.com/hechenqingyuan/gitwms)上公开下载的代码中很多人觉得在线设计报表这个功能比较不错,但是很多人也会有疑问.这边文章就简单讲解一下如何开发这个功能的,供大家学习参考,如果有任何疑问可以直接联系我,当然也有很多不足之处希望大家多多谅解和指点. 一. 各种需求报表以及打印 最开始之初在Web上做打印是每个打印也都会做一个页面,利用的是浏览器自身带的打

datable-默认参数列表

1 options { 'paging': false, 'scrollY': true, 'scrollX': true, 'scrollCollapse': false, 'ordering': false, 'searching': false, 'serverSide': false, 'info': false, 'processing': true, 'deferRender': true, 'jQueryUI': false, 'retrieve': true, 'destroy'

吉特仓储管系统(开源WMS)--分享两月如何做到10W+的项目

在此文开篇之处先特别申明,此文在有些人的眼中会有广告的嫌疑,但是本人不想将其作为一个广告宣传的文章,在此提到软件内容部分请大家予以谅解和包含,作为时间不算短的程序员给大家分享一些自己开发吉特仓储管理软件相关的经验和坑,当然还有一些自己从中获利的方式,不能说给大家指条明路吧,算是作为程序开发人的相互经验交流. 此文本来想写在国庆假期之前的,但是那段时间公司事情刚好很忙,所以没有来得及写此文.当时要搞Solr搜索引擎,因为自己不熟悉java程序所以在弄得过程中有些费力,而且自己本身也不是一心苦心专研

dataTable可以做的事情

dt.thxopen.com/example/ $(document).ready(function(){     $("#example").dataTable({         //功能启用|禁用         "paging": false,         "ordering": false,         "info": false,                  //默认排序         "