<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>곱셈 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%ea%b3%b1%ec%85%88/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Thu, 23 Feb 2023 00:12:47 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.1</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>곱셈 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 1629번 (곱셈, C++, 분할 정복) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/baekjoon-1629-c-recursion/3621/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/baekjoon-1629-c-recursion/3621/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 01 Jan 2023 10:25:21 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1629]]></category>
		<category><![CDATA[1629번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[곱셈]]></category>
		<category><![CDATA[모듈러 산술]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1629]]></category>
		<category><![CDATA[백준 1629번]]></category>
		<category><![CDATA[분할정복]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[재귀]]></category>
		<category><![CDATA[지수법칙]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=3621</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1629번 곱셈 문제를 풀이한 내용의 글입니다. 모듈러 연산 / 지수법칙이 사용되고 재귀를 이용합니다. (This is an article that solves the multiplication problem of BAEKJOON 1629. Modular operations / exponential laws are used and recursion is used.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/baekjoon-1629-c-recursion/3621/">백준 1629번 (곱셈, C++, 분할 정복) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">곱셈</h1>



<p class="has-medium-font-size wp-block-paragraph"><a href="https://www.acmicpc.net/problem/1629" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1629</a></p>



<div style="height:52px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table" style="margin-top:0;margin-right:0;margin-bottom:0;margin-left:0"><table class="has-border-color has-ast-global-color-1-border-color has-fixed-layout" style="border-width:1px"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">0.5 초 (추가 시간 없음)</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">80202</td><td class="has-text-align-left" data-align="left">21806</td><td class="has-text-align-left" data-align="left">16017</td><td class="has-text-align-left" data-align="left">26.282%</td></tr></tbody></table></figure>



<div style="height:61px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size wp-block-paragraph">자연수 A를 B번 곱한 수를 알고 싶다. </p>



<p class="has-medium-font-size wp-block-paragraph">단 구하려는 수가 매우 커질 수 있으므로 이를 C로 나눈 나머지를 구하는 프로그램을 작성하시오.</p>



<div style="height:54px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size wp-block-paragraph">첫째 줄에 A, B, C가 빈 칸을 사이에 두고 순서대로 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">A, B, C는 모두 2,147,483,647 이하의 자연수이다.</p>



<div style="height:57px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size wp-block-paragraph">첫째 줄에 A를 B번 곱한 수를 C로 나눈 나머지를 출력한다.</p>



<div style="height:69px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">10 11 12</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>문제를 만든 사람:&nbsp;<a href="https://www.acmicpc.net/user/author5" target="_blank" rel="noreferrer noopener">author5</a></li>
</ul>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/124" target="_blank" rel="noreferrer noopener">수학</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/39" target="_blank" rel="noreferrer noopener">분할 정복을 이용한 거듭제곱</a></li>
</ul>



<div style="height:51px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<div style="height:63px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제의 포인트</h2>



<p class="has-medium-font-size wp-block-paragraph">문제에서 구하는 내용은 간단하다</p>



<p class="has-medium-font-size wp-block-paragraph">A ^ B % C 의 값을 구하는 것</p>



<p class="has-medium-font-size wp-block-paragraph">A, B, C는 모두 2,147,483,647 이하의 자연수이므로 </p>



<p class="has-medium-font-size wp-block-paragraph">&#8211; A를  2,147,483,647번(약 21억) 곱하는 연산으로 시간 초과 =&gt; 2,147,483,647^2,147,483,647</p>



<p class="has-medium-font-size wp-block-paragraph">&#8211; 연산중 변수 값의 오버플로우로 인한 오류</p>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">위의 문제를 해결하기 위해서는 </p>



<p class="has-medium-font-size wp-block-paragraph">모듈러 산술 / 지수법칙을 사용하여 해결할 수 있다. </p>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-default" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-small-font-size wp-block-paragraph">모듈러 산술 : <a href="https://sskl660.tistory.com/75" target="_blank" rel="noreferrer noopener">https://sskl660.tistory.com/75</a></p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1585" height="324" src="https://lycos7560.com/wp-content/uploads/image-760.png" alt="" class="wp-image-3630" srcset="https://lycos7560.com/wp-content/uploads/image-760.png 1585w, https://lycos7560.com/wp-content/uploads/image-760-300x61.png 300w, https://lycos7560.com/wp-content/uploads/image-760-768x157.png 768w, https://lycos7560.com/wp-content/uploads/image-760-1536x314.png 1536w" sizes="(max-width: 1585px) 100vw, 1585px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-small-font-size wp-block-paragraph">지수 법칙 : <a href="https://ko.khanacademy.org/math/cc-eighth-grade-math/cc-8th-numbers-operations/cc-8th-exponent-properties/a/exponent-properties-review" target="_blank" rel="noreferrer noopener">https://ko.khanacademy.org/math/cc-eighth-grade-math/cc-8th-numbers-operations/cc-8th-exponent-properties/a/exponent-properties-review</a></p>



<div style="height:37px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="602" height="118" src="https://lycos7560.com/wp-content/uploads/image-761.png" alt="" class="wp-image-3631" srcset="https://lycos7560.com/wp-content/uploads/image-761.png 602w, https://lycos7560.com/wp-content/uploads/image-761-300x59.png 300w" sizes="(max-width: 602px) 100vw, 602px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1583" height="841" src="https://lycos7560.com/wp-content/uploads/image-762.png" alt="" class="wp-image-3635" srcset="https://lycos7560.com/wp-content/uploads/image-762.png 1583w, https://lycos7560.com/wp-content/uploads/image-762-300x159.png 300w, https://lycos7560.com/wp-content/uploads/image-762-768x408.png 768w, https://lycos7560.com/wp-content/uploads/image-762-1536x816.png 1536w" sizes="(max-width: 1583px) 100vw, 1583px" /></figure>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">위의 식을 재귀로 계속 반복하여 B = 1이 될 때까지 진행</p>



<p class="has-medium-font-size wp-block-paragraph">추가적으로 B가 홀수 일 때  B  /  B-1 로 인하여 B = 0 이 되는 경우를 따로 처리해 주어야 한다.</p>



<p class="has-medium-font-size wp-block-paragraph">(필기가 가능한 태블릿을 하나 구매할까&#8230;. ㅠ)</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>

using namespace std;

int A, B, C;

// 입력을 받는 함수
void GetInput()
{
	cin >> A >> B >> C;
}

long long int Calculate(int B)
{
	if (B == 0) { return 1; } //  N ^ 0 = 1
	else if (B == 1) { return (A % C); }
	
	if (B % 2 == 0){ // 짝수일 경우
		long long int temp = Calculate(B / 2);
		return (temp * temp) % C;
	}
	else { // 홀수일 경우
		return (A * Calculate(B-1)) % C;
	}
}

int main()
{
	GetInput();
	cout &lt;&lt; Calculate(B);
	return 0;
}</pre>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="781" height="182" src="https://lycos7560.com/wp-content/uploads/image-763.png" alt="" class="wp-image-3639" srcset="https://lycos7560.com/wp-content/uploads/image-763.png 781w, https://lycos7560.com/wp-content/uploads/image-763-300x70.png 300w, https://lycos7560.com/wp-content/uploads/image-763-768x179.png 768w" sizes="(max-width: 781px) 100vw, 781px" /></figure>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">이 문제를 풀면서 내가 수학을 얼마나 못하는지 깨달았다.</p>



<p class="has-medium-font-size wp-block-paragraph">젠장</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/baekjoon-1629-c-recursion/3621/">백준 1629번 (곱셈, C++, 분할 정복) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/baekjoon-1629-c-recursion/3621/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
