公式

A - Star 解説 by en_translator


If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.


This problem can be solved by simulating the process of increasing the number of coins one by one, until it becomes a multiple of \(100\). Be careful of the case where \(X\) is already a multiple of \(X\).

Sample Code (C)

#include <stdio.h>
#include <stdbool.h>
int main(){
    int x;
    scanf("%d",&x);
    int ans=0;
    while(true){
        x++;
        ans++;
        if(x%100==0){
            printf("%d\n",ans);
            return 0;
        }
    }
}

There is another solution. If you can find “the multiple of \(100\) that is greater than \(X\) and nearest to \(X\),” then the desired answer is the different between that value and \(X\). This can be found with a proper combination of arithmetic operations.

Sample Code (Python)

X = int(input())
goal = X//100*100 + 100
print(goal - X)

投稿日時:
最終更新: