2012-2013 ACM-ICPC, NEERC, Central Subregional Contest C Sequence (打表)

打个表找找规律,到24445的时候乘2以后产生了0出现循环。

一般地,判断循环节是否存在可以用Floyd判圈算法。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int ans[]
{
-1
,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[]
{
48889
,77789
,155578
,111356
,122227
,244445
};

int main()
{

    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n ;
    scanf("%d",&n);
    printf("%d\n",n>=25?b[(n-25)%6]:ans[n]);
    return 0;
}

 

posted @ 2015-09-03 18:20  陈瑞宇  阅读(217)  评论(2编辑  收藏  举报