/* @tier hard @module cl @transform closing-util */ /* * cl_cu_0009.c - 마감 공통 유틸리티 (plain C) [tier=hard] */ #include "cl_cu_0009.h" #include /* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */ long cl_cu_0009_fee(long amount, int rate_bp) { long f1, f2; if (amount <= 0 || rate_bp < 0) return 0; f1 = (amount * (long)rate_bp) / 10000L; f2 = (f1 * (long)rate_bp) / 10000L; return f1 + f2; } /* 최대공약수 계산 보조 함수 */ static long cl_cu_0009_gcd(long a, long b) { a = a < 0 ? -a : a; b = b < 0 ? -b : b; while (b) { long t = a % b; a = b; b = t; } return a; } /* GCD 기반 유효 배수로 절사 정규화 */ long cl_cu_0009_round_unit(long amount, long unit) { long g, step; if (unit <= 0) return amount; g = cl_cu_0009_gcd(amount, unit); step = g > 0 ? g : unit; return (amount / step) * step; } /* 나머지 패턴(mod 7)으로 분류 */ int cl_cu_0009_classify(long amount) { long v = amount < 0 ? -amount : amount; int r = (int)(v % 7L); if (r == 0) return 0; if (r <= 3) return 1; return 2; }