• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Codeforces GYM 100114 C. Sequence 打表

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

C. Sequence

Time Limit: 1 Sec  

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100114

Description

Integer sequences are very interesting mathematical objects. Let us examine a sequence generated with the use of two operations: doubling and “digit sorting”. The latter operation consists in ascending-order sort of the individual digits in the decimal representation of the argument. For example, “digit sorting” of number 5726 gives 2567. The first member of the considered sequence is 1. To generate a member of the sequence from the previous member, double the previous one and apply “digit sorting” to the result. The first 15 members of the sequence are as follows: 1, 2, 4, 8, 16, 23, 46, 29, 58, 116, 223, 446, 289, 578, 1156, … Write a program to determine the value of the n-th member of this sequence.

Input

The first line contains an integer n, the number of sequence member to be calculated.

Output

The output file should contain a single integer k, the value of the n-th member of the sequence

Sample Input

1

Sample Output

1

HINT

1 ≤ n ≤ 2 147 483 647.

题意

1, 2, 4, 8, 16, 23, 46, 29, 58, 116, 223, 446, 289, 578, 1156

规律是上一个,是前一个数乘以2之后,数字按字典序排列之后的样子

题解:

打表之后,发现后面都是6个一个循环的,直接输出就好了

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>

using namespace std;

int a[40]={0,1,2,4,8,16,23,46,29,58,116,223,446,289,578,1156,1223,2446,2489,4789,5789,11578,12356,12247,24449};
int b[10]={48889,77789,155578,111356,122227,244445};
int n;

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d",&n);
    if(n<=24) printf("%d\n",a[n]);
        else printf("%d\n",b[(n-25)%6]);
    return 0;
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c博客06-2019-结构体&amp;文件发布时间:2022-07-13
下一篇:
C#获取物理网卡Mac地址发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap