function count_n($limit, $n) { if ($limit < $n) { return 0; } if ($limit == $n) { return 1; } $power = floor(log10($limit)); $unit = pow(10, $power); $high = floor($limit / $unit); $low = $limit % $unit; return $high * $power * $unit / 10 + (($high > $n)? $unit: (($high == $n)? 1 + $low: 0)) + count_n($low, $n); } echo count_n(100000000, 1); // 80000001
2. [代码]最初用 newLisp 写的函数
(define (count-n limit n) (if (< limit n) 0 (= limit n) 1 (letn (high (int ((string limit) 0)) low (int (1 (string limit))) power (int (log limit 10))) (+ (count-n low n) (* high power (pow 10 (- power 1))) (if (> high n) (pow 10 power) (= high n) (+ 1 low) 0))))) (println (count-n 100000000 1))
陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章
Windows 11 KB5054979中的新功能以及如何解決更新問題
3 週前ByDDD
如何修復KB5055523無法在Windows 11中安裝?
2 週前ByDDD
Inzoi:如何申請學校和大學
4 週前ByDDD
如何修復KB5055518無法在Windows 10中安裝?
2 週前ByDDD
Roblox:Dead Rails - 如何召喚和擊敗Nikola Tesla
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SublimeText3 Linux新版
SublimeText3 Linux最新版

記事本++7.3.1
好用且免費的程式碼編輯器