Skip to content

Latest commit

 

History

History
91 lines (74 loc) · 1.86 KB

0010.运营商活动.md

File metadata and controls

91 lines (74 loc) · 1.86 KB

10. 运营商活动

题目链接

C++

#include<iostream>
using namespace std;
int main() {
    int m, k;
    while (cin >> m >> k) {
        if (m == 0 && k == 0) break;
        int sum = m + m / k; // 第一轮回得到总话费
        int count = m / k + m % k; // 额外话费 = 赠送+剩余话费 
        while (count / k != 0) { // 只要额外话费大于 k 就还能获得 剩余话费  
            sum += count / k;
            count = count / k + count % k;
        }
        cout << sum << endl;
    }
}

Java

import java.util.*;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int m = sc.nextInt();
            int k = sc.nextInt();
            if (m == 0 && k == 0) break;
            int res = 0;
            int sum = m + m / k;
            int remain = m / k + m % k;
            while (remain / k != 0) {
                sum += remain / k;
                remain = remain / k + remain % k;
            }
            System.out.println(sum);
        }
    }
}

python

while True:
    M, K = map(int, input().split())
    if M == 0 and K == 0:
        break
    res = M
    while M >= K:
        res += M // K
        M = M // K + M % K
    print(res)

Go

Js

C

#include <stdio.h>

int main() {
    int m, k;
    while (scanf("%d%d", &m, &k) == 2) {
        if (m == 0 && k == 0) break;
        int sum = m + m / k; // 第一轮回得到总话费
        int count = m / k + m % k; // 额外话费 = 赠送+剩余话费 
        while (count / k != 0) { // 只要额外话费大于 k 就还能获得 剩余话费  
            sum += count / k;
            count = count / k + count % k;
        }
        printf("%d\n", sum);
    }
    return 0;
}