LightOJ1109 False Ordering 筛法求约数个数+结构体排序
来源:互联网 发布:linux c语言多线程 编辑:程序博客网 时间:2024/05/18 01:29
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
这题数据量太小啦,所以暴力也能过。
#include <iostream>#include <cstdio>#include <map>#include <set>#include <vector>#include <queue>#include <stack>#include <cmath>#include <algorithm>#include <cstring>#include <string>using namespace std;#define INF 0x3f3f3f3ftypedef long long LL;struct num{ int a; int b;}s[10005];void p(){ for(int i=1;i<=1000;i++){ s[i].a=i; s[i].b=1; } for(int i=2;i<=1000;i++){ for(int j=i;j<=1000;j+=i){ s[j].b++; } }}bool cmp(num x,num y){ return x.b==y.b? x.a>y.a:x.b<y.b;}int main(){std :: ios :: sync_with_stdio (false); p(); sort(s+1,s+1001,cmp); int t,n; scanf("%d",&t); for(int i=1;i<=t;i++){ scanf("%d",&n); printf("Case %d: %d\n",i,s[n]); } return 0;}
0 0
- LightOJ1109 False Ordering 筛法求约数个数+结构体排序
- Lightoj1109——False Ordering(数学+结构体)
- lightoj1109 - False Ordering
- Lightoj1109——False Ordering(简单数学)
- LIGHT OJ 1109 - False Ordering 【因子个数】
- lightoj 1109 - False Ordering 因式分解+排序
- LOJ 1109 - False Ordering (排序)
- False Ordering
- LightOJ 1109 False Ordering
- LightOJ 1109 False Ordering
- 约数个数
- 约数个数
- 约数个数
- 约数个数
- 约数个数
- 【OI结构】约数个数公式以及它的证明
- Light OJ 1109 - False Ordering
- lightoj-1109 - False Ordering【思维】
- CSS3实现一个开关按钮控件
- 如何计算时间复杂度
- 函数指针的学习
- 安卓7.0谷歌官方底包线刷+刷入第三方recovery+解密+root
- ANDROID应用开发架构概述
- LightOJ1109 False Ordering 筛法求约数个数+结构体排序
- 驱动程序分层、分隔思想
- oracle 限制用户密码输入错误次数
- javascript 思维导图
- C语言基础--常用字符串处理函数
- java中String的七种用法
- linux下对端口的操作
- windows&linux多线程互斥
- BZOJ3451 Tyvj1953 Normal