zoukankan      html  css  js  c++  java
  • 计算1+11+111+1111+........

    f(n)=f(n-1)+10^n;

     public static void main(String[] args) {
            int n=2017;
            long temp=1;
            for(int i=1;i<n;i++){
                temp+=func(i);
            }
            System.out.println(temp);
        }

        private static long func(int i) {
            // TODO Auto-generated method stub
            long sum;
            if(i==0){
                sum=1;
            }
            else{
                sum=(long) (Math.pow(10, i)+func(i-1));    
            }
            return sum;
        }

  • 相关阅读:
    Mysql其他
    Linux大全
    Django-你想知道的都在这里
    k8s
    极速安装k8s 快速融入学习
    flask orm
    Elasticsearch
    1爬虫
    MY git 操作
    docker 骚操作
  • 原文地址:https://www.cnblogs.com/blythe/p/7375277.html
Copyright © 2011-2022 走看看