코딩스터디

7193. 승현이의 수학공부

애플앤마블 2019. 5. 12. 22:22
반응형
SMALL

Math by Hare Krishna from the Noun Project

본 문제는 swexpertacademy의 문제임을 알립니다. 아래 URL 참조

 

n진법의 수를 n-1진법으로 나눈 나머지는 각자리 수를 더하여 N-1로 나누는 원리를 사용하면 됩니다.

 

#include<iostream>
#include<math.h>
#include<string>
using namespace std;

int main(){
    
    int T;
    cin>>T;
    for(int t=1; t<=T; t++){
        
        cout<<"#"<<t<<" ";
        long N;
        string X;
        cin>>N>>X;
        long sum=0;
        for(int j=0; j<X.length(); j++){
            sum+=X[j]-48;
        }
        cout<<sum%(N-1)<<'\n';
    }
    return 0;
}

 

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWksRkI6AR0DFAVE

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

www.swexpertacademy.com

 

반응형
LIST