알고리즘/문제 [BOJ/백준 - 15829] Hashing - 문제 풀이: https://www.acmicpc.net/problem/15829 15829번: Hashing APC에 온 것을 환영한다. 만약 여러분이 학교에서 자료구조를 수강했다면 해시 함수에 대해 배웠을 것이다. 해시 함수란 임의의 길이의 입력을 받아서 고정된 길이의 출력을 내보내는 함수로 정 www.acmicpc.net This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters public class BOJ_15829 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int len = Integer.parseInt(br.readLine()); String str = br.readLine(); long[] temp = new long[50]; temp[0] = 1; for(int i=1; i<50; i++){ temp[i] = (temp[i-1] * 31) % 1234567891; } long sum = 0; for(int i=0; i<len; i++){ int a = str.charAt(i)-96; sum+=(a*temp[i]); } System.out.println(sum%1234567891); } } view raw BOJ_15829.java hosted with ❤ by GitHub 제곱이라고 Math.pow() 쓰면 오버플로난다 별다른건 없고 미리 배열에다가 제곱수를 구해놓고 계산한다 공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기Time to lazy Contents 당신이 좋아할만한 콘텐츠 [BOJ/백준 - 1541] 잃어버린 괄호 2022.01.12 [BOJ/백준 - 10845] 큐 2022.01.11 [BOJ/백준 - 1744] 수 묶기 2022.01.11 [BOJ/백준 - 13904] 과제 2022.01.11 댓글 0 + 이전 댓글 더보기