6 条题解

  • 0
    @ 2023-12-11 20:57:38

    #include <stdio.h> // 将十进制整数 x 转换为 n 进制 void convertToBase(int x, int n) { int xBase[100], i = 0; while (x > 0) { xBase[i] = x % n; x /= n; i++; } for (int j = i - 1; j >= 0; j--) { printf("%d", xBase[j]); } printf("\n"); } // 判断 x 是否为 n 的幂次方 void isPowerOfN(int x, int n) { if (x == 1) { printf("yes\n"); return; } for (int i = 2; i * i <= x; i++) { int power = i; while (power <= x) { power *= i; if (power == x) { printf("yes\n"); return; } } } printf("no\n"); } int main() { int x, n; scanf("%d %d", &x, &n); // 转换为 n 进制 convertToBase(x, n); // 判断是否为 n 的幂次方 isPowerOfN(x, n); return 0; }

    信息

    ID
    960
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    递交数
    145
    已通过
    53
    上传者