公式

B - Multiple of 9 解説 by evima


(This editorial is a mirror of kyopro_friends’s PDF editorial.)

You are asked to input \(N\) as a string, and check if the sum of the digits is a multiple of \(9\).

Sample Code in C

char s[200010];
int main(){
    scanf("%s",s);
    int len=strlen(s);
    int sum=0;
    for(int i=0;i<len;i++)sum+=s[i]-'0';
    if(sum%9==0){
        puts("Yes");
    }else{
        puts("No");
    }
}

Note that, in languages that can handle with multiple-length integer like Python, it may be directly judged whether \(N\) is a multiple of \(9\) or not.

Sample code in Python

N=int(input())
if N%9 == 0:
    print("Yes")
else:
    print("No")

投稿日時:
最終更新: