Çözüldü Kombinasyon - Basamak Analizi - Programlama

Konusu 'Matematik - Geometri' forumundadır ve Honore tarafından 31 Ağustos 2019 başlatılmıştır.

Yüklüyor...
  1. Honore

    Honore Yönetici Yönetici

    Mesajlar:
    11.054
    Beğenileri:
    652
    Cinsiyet:
    Bay
    Meslek:
    Müh. (Elk./Bilg.)
     
    : Fortran

  2. Benzer Konular: Kombinasyon Basamak
    Forum Başlık Tarih
    Matematik - Geometri Basamak Analizi - Kombinasyon - Programlama 15 Haziran 2010
    Polinomlar, Permütasyon, Kombinasyon, Olasılık ve Binom Açılımı Olasılıkta Kombinasyon Kullanımı - Faktöriyel - Koşullu Olasılık Salı 14:21
    Hatalı - Tekrarlanmış Sorular veya Çözümler (Faulty - Repeated Questions or Solutions) Olasılık - Kombinasyon (Seçenekler yanlış) 25 Şubat 2026
    Polinomlar, Permütasyon, Kombinasyon, Olasılık ve Binom Açılımı Binom Olasılık Dağılımı - Kombinasyon - Programlama 8 Ocak 2026
    Polinomlar, Permütasyon, Kombinasyon, Olasılık ve Binom Açılımı Kombinasyon - Faktöriyel - Olasılık 20 Eylül 2025

  3. Honore

    Honore Yönetici Yönetici

    Mesajlar:
    11.054
    Beğenileri:
    652
    Cinsiyet:
    Bay
    Meslek:
    Müh. (Elk./Bilg.)
    www.mathful.com'daki yapay zekânın 463 saniyede verdiği 21 sayfalık incelemesiyle çözümü (ektedir) ve sonundaki özeti:
    [​IMG]
    https://i.ibb.co/39dkRvWT/Mathful-AI-Basamaklar-Toplami.png

    Bilgisayar programlamayla ilgilenen öğrenciler için yararlı olacağı düşüncesiyle www.workik.com sitesindeki yapay zekâya yaptırdığım (çok küçük bir hatasını düzelttim) Fortran programı:
    [​IMG]
    https://i.ibb.co/RpT9cVpS/rakamlar-toplami-Fortran.png

    Program:
    Kod:
    ! Program generated by the AI at www.workik.com
    ! I have slightly modified and corrected one mistake by placing the
    ! variable d at the proper place.
    
    ! Explanation:
    ! We use a dynamic programming approach to count the number of numbers of length
    ! max_digits=19 whose digits sum to 2.
    ! dp(pos, s) stores how many ways to form a number with exactly pos digits and the digit
    ! sum equal to s.
    ! We allow leading zeros to handle all numbers from 0 up to 10^19 - 1 uniformly.
    ! Since the problem counts natural numbers from 1 to 10^19 and 0 is excluded but has
    ! digit sum 0, no subtraction is necessary.
    ! The upper limit 10^19 is represented as a 20-digit number, but since we only use 19
    ! digits from 0 to 10^19-1, it's consistent.
    ! The count of numbers with digit sum 2 is the answer.
    ! The program should execute fast because dp is very small (only 20 x 3 in size).
    ! The integer kind(8) (64-bit integers) is used for holding the result as it can be quite large.
    program count_sum_digits_two
      implicit none
      integer, parameter :: max_digit_sum = 2
      integer, parameter :: max_digits = 19
      integer(8) :: result
      integer :: i, sum_digit, d
      integer(kind=8), dimension(0:max_digits,0:max_digit_sum) :: dp = 0_8
    
      ! dp(pos, s) = number of ways to form a number with 'pos' digits summing to 's'
    
       dp(0,0) = 1_8
    
      ! For each digit position
      do i = 1, max_digits
        do sum_digit = 0, max_digit_sum
           do d = 0, 9
            if (sum_digit - d >= 0) then
              dp(i,sum_digit) = dp(i,sum_digit) + dp(i-1,sum_digit - d)
            end if
          end do
        end do
      end do
    
      ! We want numbers from 1 to 10^19 with digit sum = 2
      ! dp(max_digits, 2) includes numbers with leading zeros, i.e., numbers with fewer digits padded with zeros
      ! This counts numbers from 0 to 10^19-1 with digit sum 2.
      ! Since 0 has digit sum 0, no correction is required.
      ! Also, 10^19 itself is a 1 followed by 19 zeros, digit sum=1, so it does not count anyway.
    
      result = dp(max_digits, max_digit_sum)
    
      write(6,10)"Number of natural numbers from 1 to 10^19 with digit sum 2: ", result
    
    10 format (a,i3)
    
    end program count_sum_digits_two

    Ekli Dosyalar:

Sayfayı Paylaş