Lexicographic permutations

来源:互联网 发布:excel编程用什么语言 编辑:程序博客网 时间:2024/06/05 10:17

https://projecteuler.net/problem=24

Lexicographic permutations

Problem 24

Published on Friday, 16th August 2002, 06:00 pm; Solved by 75662; Difficulty rating: 5%

A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:

012   021   102   120   201   210

What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?

这道题懒得编程了,就纯粹靠手工计算的结果,过程如下:

9!=362880,我们要算第100万个,所以第一个数字排在第三位,也就是    2,接下来要算第274240位数 (1000000 - 9! * 2)

8!=40320,经过计算:8!*6 < 274240 < 8!*7,所以第二个数字,排在剩下数字的第7位,也就是:7,接下来算第32320位数(274240 - 8! * 6)

依次类推:直到剩下最后两位6和0,要求第二位数,那就是60了。

所以结果是:2783915460


用计算机算也一样,懒得写程序了

0 0
原创粉丝点击