Codeforces GYM 100114 C. Sequence 打表

來源:互聯網
上載者:User

標籤:

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.

InputThe first line contains an integer n, the number of sequence member to be calculated.OutputThe output file should contain a single integer k, the value of the n-th member of the sequenceSample Input

1

Sample Output1HINT1 ≤ 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;}

 

Codeforces GYM 100114 C. Sequence 打表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.