알고리즘 문제풀기/SW Expert Academy
7193. 승현이의 수학공부(D3)
알광(Algwang)
2019. 3. 6. 17:33
문제링크 : https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWksRkI6AR0DFAVE
- 소스 코드 -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import java.util.Scanner; // 0보다 크거나 같은 모든 k에 대해 // n^(k) % (n-1) ≡ 1을 만족한다. // 이것만 알면 쉽게 풀 수 있는 문제 !! public class Solution7193 { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int T=scan.nextInt(); for(int test_case=1;test_case<=T;test_case++) { int n=scan.nextInt(); String str=scan.next(); n--; int result=0; for(int i=0;i<str.length();i++) { result+=(str.charAt(i)-'0'); } result%=n; System.out.printf("#%d %d\n",test_case,result); } } } | cs |