zoukankan      html  css  js  c++  java
  • 洛谷 1062 NOIP2006普及T4 数列

    【题解】

      鲜活的水题。。我们把数列换成k进制的,发现数列是001,010,011,100,101,110,111...,而第m项用k进制表示的01串刚好就是m的二进制的01串。于是我们预处理k的幂,把n化成2进制的,在用这个01串求数列第n项即可。

      

     1 #include<cstdio>
     2 #include<algorithm>
     3 #define rg register
     4 #define N 50
     5 #define LL long long 
     6 using namespace std;
     7 int n,k,a[200],tot;
     8 LL exp[200],ans=0;
     9 inline int read(){
    10     int k=0,f=1;  char c=getchar();
    11     while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    12     while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
    13     return k*f;
    14 }
    15 int main(){
    16     k=read(); n=read(); exp[0]=1;
    17     for(rg int i=1;i<=N;i++) exp[i]=exp[i-1]*k;
    18 //    for(rg int i=1;i<=10;i++) printf("%lld ",exp[i]); puts("");
    19     while(n){
    20         a[tot++]=n%2;
    21         n/=2;
    22     }
    23     for(rg int i=0;i<=tot;i++) if(a[i]) ans+=exp[i];
    24     printf("%lld
    ",ans);
    25     return 0;
    26 }
    View Code
  • 相关阅读:
    InitializingBean
    线程池
    maven
    mysql主从库
    zookeeper
    分布式服务框架 Zookeeper -- 管理分布式环境中的数据
    远程调试
    enum
    注解
    Shell错误[: missing `]'
  • 原文地址:https://www.cnblogs.com/DriverLao/p/8792971.html
Copyright © 2011-2022 走看看