编程介的小学生 2019-03-23 14:48 采纳率: 0.4%
浏览 216

平方根和的平均问题,如何利用C语言的方式解决这个问题的算法

Problem Description
Find the biggest integer n (1 <= n <= N) and an integer x to make them satisfy

Input
The input consists of several test cases. Each test case contains a integer N, 1<=N<=10^18.The input ends with N = 0.

Output
In one line for each case, output two integers n and x you have found.

Sample Input
1
2
0

Sample Output
1 1
1 1

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-08 12:06
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    #include <stdio.h>
    
    int main() {
        int n;
        scanf("%d", &n);
        if(n == 0)
            return printf("1 1\n");
        
        long long sum = 0;
        while(n > 0){
            sum += n % 4;
            n /= 4;
        }
        printf("%lld %lld\n", sum/3, sum - sum/3);
        return 0;
    }
    
    评论

报告相同问题?