2 条题解

  • 1
    @ 2025-11-28 19:58:22
    /**
     *    author: 小飞侠cy
     *    created: 2025.11.28 19:49:47
     */
    #include <iostream>
    using namespace std;
    int check(int x)
    {
        int sum = 0;
        int t = x;//替换 x 为 t, 因为后面还要用到 x 的数值
        int has_0 = 0;//数位是否包含 0
        while(t)
        {
            sum += t % 10;//计算每一位的数字之和
            if(t % 10 == 0) has_0 = 1;//某一位是 0 标记一下
            t /= 10;
        }
        if(!has_0 && x % sum == 0) return 1;//满足条件则该数字是幸运飞侠数
        else return 0;
    }
    int main()
    {
        int cnt = 0;//第几个幸运飞侠数
        for(int i = 1; ; ++ i)//死循环
        {
            if(check(i)) cnt ++;
            if(cnt == 2025)
            {
                cout << i << '\n';
                return 0;
            }
        }
        return 0;
    }
    
    • -1
      @ 2025-11-27 21:04:29
      #include<bits/stdc++.h>
      using namespace std;
      
      int main()
      {
          int cnt = 0;
          auto check = [](int n) {
              int total = 0, soure = n;
              while (n) {
                  if (n % 10 == 0) return false;
                  total += n % 10;
                  n /= 10;
              }
              return total != 0 && soure % total == 0;
          };
          for (int i = 0; ; i++) {
              if (check(i)) cnt ++;
              if (cnt == 2025) {
                  cout << i << '\n';
                  break;
              }
          }
          return 0;
      }
      
      • 1

      信息

      ID
      5625
      时间
      1000ms
      内存
      256MiB
      难度
      8
      标签
      递交数
      204
      已通过
      30
      上传者