zoukankan      html  css  js  c++  java
  • (Problem 40)Champernowne's constant

    An irrational decimal fraction is created by concatenating the positive integers:

    0.123456789101112131415161718192021...

    It can be seen that the 12th digit of the fractional part is 1.

    If dn represents the nth digit of the fractional part, find the value of the following expression.

    d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000

    #include <stdio.h>
    
    int solve()
    {
        int i, k, result, n, t, temp;
        int s[8], a[101];
        i = k = 0;
        n = result = 1;
        t = 0;
        while(1) {
            temp = n;
            i = 0;
            while(temp) {
                s[i++] = temp % 10;
                temp /= 10;
            }
            i--;
            while(i >= 0) {
                a[k] = s[i];
                t++;
                if(t == 1 || t == 10 || t == 100 || t == 1000 || t == 10000 || t == 100000 || t == 1000000) {
                    result *= a[k];
                    if(t == 1000000)  return result;
                }
                if(k == 100) {
                    k = 1;
                } else {
                    k++;
                }
                i--;
            }
            n++;
        }
    }
    
    int main(void)
    {
        printf("%d
    ",solve());
        return 0;
    }
    Answer:
    210
    作者:acutus
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    cmake使用
    CMake...
    信息熵相关知识总结
    最强NLP模型-BERT
    问答系统总结
    检索问答模型
    文本分类-TextCNN
    机器学习-Logistic回归
    Attention注意力机制介绍
    机器学习-聚类Clustering
  • 原文地址:https://www.cnblogs.com/acutus/p/3509922.html
Copyright © 2011-2022 走看看