求1-n中x(0-9)的个数
发布日期:2021-05-10 16:10:17 浏览次数:9 分类:精选文章

本文共 2615 字,大约阅读时间需要 8 分钟。

C++������������������������������

���������C++������������������������������������������������������������������������������������������������������������������������������

���������������

#include 
#include
using namespace std;
typedef long long ll;
ll count(ll n, ll x) {
ll cnt = 0;
ll power = 10;
for (ll i = 1; i <= n; i *= power) {
ll high = i / 10;
// ������������������������
if (x == 0) {
if (high) high--;
else break;
}
cnt += high * i;
// ������������������i������������������
ll current = (n / i) % 10;
if (current > x) {
cnt += i;
} else if (current == x) {
cnt += n - (i * (n / i)) + 1;
}
// ���������1������power���������
if (power == 10) {
if (i == 10) {
power = 100;
} else {
power = 0;
}
}
}
return cnt;
}
int main() {
return 0;
}

���������������

  • ���������������
    • ���������������������������������count������������������������
    • ������������������������������������������power���������10������������
    • ������������������������������������������������
    • ������������������������������������i���������������������������i iota Macro���������������������������
    • ���������������������������������������������������������������������������������������������
    1. ���������������
      • ������������������������������������������������������������������������������
      • ������������������������������������������������������������������������������
      • ���������������������������������������������������������������������������������������������������
      1. ���������������������
        • ���������������������������������������������������������������������������������������������������
        • ���������������������������������������������������������������
        • ������������������������������������������������������������������������������
        1. ���������������
          • ������������������������10���������������������������������������

          ������������snprintf������������printf������������������������������������������������������������������������������������

          #include 
          int main() {
          char buffer[1024];
          snprintf(buffer, sizeof(buffer), "���������������%d", count(100000000, 12));
          puts(buffer);
          return 0;
          }

          ������������������������������������������������������������������������������������������������n���x���������������������������������������������������������������������������������������

          ���������������������������������������������������������������������������

    上一篇:杭电2019多校第八场 HDU——6659 Acesrc and Good Numbers(思维打表+oeis)
    下一篇:杭电2019多校第七场 HDU——6651 Final Exam(思维+简单构造)

    发表评论

    最新留言

    路过按个爪印,很不错,赞一个!
    [***.219.124.196]2025年04月08日 10时20分02秒