void InternalDivide(char * a) { size_t len = strlen(a); if ( len == 1 && *a == '0' ) throw("ㅗ"); if ( m_length < len ) ForcePut("0"); char* buf = new char[m_length]; size_t blen = 0; char* ptr = m_ptr; size_t prevlen = m_length; for ( size_t posValid = len - 1; posValid < m_length; ) { bool skip = false; if (InternalCompare(a) < 0) break; if ( m_ptr[posValid] >= *a ) { char tch = m_ptr[posValid + 1]; m_ptr[posValid + 1] = 0; bool k = strcmp(m_ptr, a) >= 0; m_ptr[posValid + 1] = tch; if (k == true) goto S; } if ( posValid >= m_length ) break; posValid++; buf[blen++] = 0; skip = true; S: char* lefts = new char[posValid + len]; memcpy(lefts, m_ptr, posValid + len - 1); lefts[posValid + len - 1] = 0; const char* bt[] = { "2", "3", "4", "5", "6", "7", "8", "9" }; int i = 2; for ( ; i < 10; i++) { BigInteger bi; bi.Add(a); bi.Mul(bt[i-2]); if ( bi.InternalCompare(lefts) >= 0 ) break; } BigInteger result; result.Add(a); if ( i >= 3 ) result.Mul(bt[i-3]); char* subt_ex10 = new char[m_length - posValid + skip + len]; memcpy(subt_ex10, result.m_ptr, result.m_length); int puts = m_length - posValid - len + 1; if ( puts > 0 ) while ( puts-- ) subt_ex10[result.m_length + puts] = '0'; subt_ex10[m_length - posValid + skip + len - 1] = 0; InternalSubtract(_strrev(subt_ex10)); delete[] lefts; delete[] subt_ex10; buf[blen++] = i - 1; if ( prevlen > m_length ) { posValid = len - 1; prevlen = m_length; buf[blen++] = 0; } } size_t bpl = blen; char* tmp = new char[blen + 1]; while ( --blen ) tmp[blen] = buf[blen] + '0'; *tmp = *buf + '0'; tmp[bpl] = 0; delete[] m_ptr; delete[] buf; m_length = bpl - 1; m_ptr = tmp; }


딱 나누어 떨어지는 수는 정상적으로 되는데

그 외의 것들은 전부 곱하기 연산으로 돌아감 ㅡ,ㅡ

전체 코드 : https://ideone.com/xDay3Y