中国(北方)大学生程序设计训练赛(第三周)(Interesting sequence-找规律)
原创
©著作权归作者所有:来自51CTO博客作者mb62d7cd05038ca的原创作品,请联系作者获取转载授权,否则将追究法律责任
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 sort-ing” 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.
n (1<=n<=1e9)
打表发现有循环节
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define
ll f[MAXN];
int main() {
// freopen("B.in","r",stdin);
int T=read();
f[1]=1;
Fork(i,2,100) {
f[i]=f[i-1]*2;
vi v;
while(f[i]) v.pb(f[i]%10),f[i]/=10;
sort(ALL(v));
Rep(j,SI(v)) f[i]=f[i]*10+v[j];
}
For(kc,T) {
ll a=read();
printf("Case #%d: ",kc);
if (a>25) {
a-=25;
a%=6;
a+=25;
}printf("%lld\n",f[a]);
}
return 0;
}