LightOJ 1109 - False Ordering (因子数打表排列)
2016-02-09 17:49
337 查看
1109 - False Ordering
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.
Each case contains an integer n (1 ≤ n ≤1000).
ac代码:
![]() ![]() | PDF (English) | Statistics | Forum |
Time Limit: 1 second(s) | Memory Limit: 32 MB |
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
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 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 .num); } return 0; }
相关文章推荐
- supervisor
- cocos2dx 文字遮罩ClipingNode与中文乱码解决
- 加载 xib 文件
- 1050. 螺旋矩阵(25)
- 一个命令永久禁用Win10驱动程序强制签名
- ZOJ 3622 Magic Number(数)
- nyoj48过河问题
- 《Python for kids》学习笔记(五)
- LeetCode题解:Word Break
- reading note 2
- POJ2823(优先队列)
- LeetCode题解:Copy List with Random Pointer
- 猴年大吉之开心刷题
- 文明3地图之一--两个大岛
- spring(IOC) 对象创建时机、对象作用域scope、对象的初始化方法和销毁方法的调用、spring容器总结
- 基于Dreamweaver的网页制作学习2----站点规划及图片的插入
- 悬浮DIV页面制作
- LeetCode题解:Single Number II
- [转]Java_List元素的遍历和删除
- spring【2】( web.xml配置中classpath:与classpath*:的区别)