<!DOCTYPE html>
	<html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
	<head>
<title>Mã Hóa | Câu 4 - Đề thi HSG tin 12 Nghệ An | Năm 2013-2014</title>
<meta name="description" content="Mã Hóa | Câu 4 - Đề thi HSG tin 12 Nghệ An | Năm 2013-2014 - Savefile - Tin tức -...">
<meta name="author" content="BÀI TẬP Ở NHÀ">
<meta name="copyright" content="BÀI TẬP Ở NHÀ [ducluu80@gmail.com]">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index, archive, follow, noodp">
<meta name="msnbot" content="all,index,follow">
<meta name="generator" content="NukeViet v4.5">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="content-language" content="vi">
<meta property="og:title" content="Mã Hóa | Câu 4 - Đề thi HSG tin 12 Nghệ An | Năm 2013-2014">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin tức - https&#x3A;&#x002F;&#x002F;baitaponha.com&#x002F;savefile&#x002F;giai-de-tin-hoc&#x002F;ma-hoa-cau-4-de-thi-hsg-tin-12-nghe-an-nam-2013-2014-44.html">
<meta property="og:site_name" content="BÀI TẬP Ở NHÀ">
<meta property="og:url" content="https://baitaponha.com/savefile/giai-de-tin-hoc/ma-hoa-cau-4-de-thi-hsg-tin-12-nghe-an-nam-2013-2014-44.html">
<link rel="shortcut icon" href="https://baitaponha.com/uploads/logo.ico">
<link rel="canonical" href="https://baitaponha.com/savefile/giai-de-tin-hoc/ma-hoa-cau-4-de-thi-hsg-tin-12-nghe-an-nam-2013-2014-44.html">
<link rel="alternate" href="https://baitaponha.com/rss/" title="Tin tức" type="application/rss+xml">
<link rel="alternate" href="https://baitaponha.com/rss/lap-trinh-python-co-ban/" title="Tin tức - Lập trình Python cơ bản." type="application/rss+xml">
<link rel="alternate" href="https://baitaponha.com/rss/giai-de-tin-hoc/" title="Tin tức - Giải đề tin học" type="application/rss+xml">
<link rel="alternate" href="https://baitaponha.com/rss/boi-gioi-tin-hoc/" title="Tin tức - Bồi giỏi tin học" type="application/rss+xml">
<link rel="alternate" href="https://baitaponha.com/rss/lap-trinh-c/" title="Tin tức - Lập trình C++" type="application/rss+xml">
<link rel="alternate" href="https://baitaponha.com/rss/thu-thuat-may-tinh/" title="Tin tức - Thủ thuật máy tính" type="application/rss+xml">
<link rel="preload" as="style" href="https://baitaponha.com/assets/css/font-awesome.min.css" type="text/css">
<link rel="preload" as="style" href="https://baitaponha.com/themes/egov/css/bootstrap.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://baitaponha.com/themes/egov/css/style.css" type="text/css">
<link rel="preload" as="style" href="https://baitaponha.com/themes/egov/css/style.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://baitaponha.com/themes/egov/css/custom.css" type="text/css">
<link rel="preload" as="style" href="https://baitaponha.com/themes/egov/css/style-green.css" type="text/css">
<link rel="preload" as="style" href="https://baitaponha.com/themes/egov/css/news.css" type="text/css">
<link rel="preload" as="script" href="https://baitaponha.com/assets/js/jquery/jquery.min.js" type="text/javascript">
<link rel="preload" as="script" href="https://baitaponha.com/assets/js/language/vi.js" type="text/javascript">
<link rel="preload" as="script" href="https://baitaponha.com/assets/js/DOMPurify/purify3.js" type="text/javascript">
<link rel="preload" as="script" href="https://baitaponha.com/assets/js/global.js" type="text/javascript">
<link rel="preload" as="script" href="https://baitaponha.com/assets/js/site.js" type="text/javascript">
<link rel="preload" as="script" href="https://baitaponha.com/themes/default/js/news.js" type="text/javascript">
<link rel="preload" as="script" href="https://baitaponha.com/assets/js/jquery/jquery.cookie.js" type="text/javascript">
<link rel="preload" as="script" href="https://baitaponha.com/themes/egov/js/main.js" type="text/javascript">
<link rel="preload" as="script" href="https://baitaponha.com/themes/egov/js/custom.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.googletagmanager.com/gtag/js?id=G-4JBZJ8SEPL" type="text/javascript">
<link rel="preload" as="script" href="https://baitaponha.com/themes/egov/js/bootstrap.min.js" type="text/javascript">
<link rel="StyleSheet" href="https://baitaponha.com/assets/css/font-awesome.min.css">
<link rel="StyleSheet" href="https://baitaponha.com/themes/egov/css/bootstrap.non-responsive.css">
<link rel="StyleSheet" href="https://baitaponha.com/themes/egov/css/style.css">
<link rel="StyleSheet" href="https://baitaponha.com/themes/egov/css/style.non-responsive.css">
<link rel="StyleSheet" href="https://baitaponha.com/themes/egov/css/custom.css">
<link rel="StyleSheet" href="https://baitaponha.com/themes/egov/css/style-green.css">
<link rel="StyleSheet" href="https://baitaponha.com/themes/egov/css/news.css">
<style type="text/css">
	body{background: #fff;}
</style>

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3247389617576546"
     crossorigin="anonymous"></script>
     <!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4JBZJ8SEPL"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-4JBZJ8SEPL');
</script>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-W4C9RPT');</script>
<!-- End Google Tag Manager -->
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-6V0WCB5SCB"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-6V0WCB5SCB');
</script>
<script async custom-element="amp-auto-ads"
        src="https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js">
</script>		
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-262364265-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-262364265-1');
</script>
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-262364265-1', '.baitaponha.com');
ga('send', 'pageview');
</script>
</head>
	<body>
	    <amp-auto-ads type="adsense"
                    data-ad-client="ca-pub-3247389617576546">
        </amp-auto-ads>
<!-- BEGIN Fanpage Facebook -->
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/vi_VN/sdk.js#xfbml=1&version=v16.0&appId=390459604647856&autoLogAppEvents=1" nonce="H8AT1lQt"></script>

<!-- END Fanpage Facebook -->
        <!-- Google Tag Manager (noscript) -->
            <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-W4C9RPT"
            height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
        <!-- End Google Tag Manager (noscript) -->
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">BÀI TẬP Ở NHÀ</h2>
		<p class="pull-right"><a title="BÀI TẬP Ở NHÀ" href="https://baitaponha.com/">https://baitaponha.com</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Mã Hóa | Câu 4 - Đề thi HSG tin 12 Nghệ An | Năm 2013-2014</h1>
		<ul class="list-inline">
			<li>Thứ năm - 11/05/2023 03:48</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
			Đây là một câu khó, một bài toán số lớn (Có tới 100 chữ số). Để giải quyết bài này chúng ta cần phải dùng đến tổ hợp, kiến thức của môn toán.&nbsp;
		</div>
				<div class="imghome">
			<img alt="Câu khó nhất đề thi năm 2013 - 2014" src="https://baitaponha.com/uploads/news/2023_05/ray-so-export.png" width="460" class="img-thumbnail" />
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			​&nbsp;<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><b><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Bài 4. MÃ HÓA</span></span></b></span></span></span><br />
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Nam rất thích thú với việc mã hóa các dữ liệu</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">. <span style="display:none">There was a science conference in gimnasium, where Petya studied, and he decided to participate in it.</span> </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Trong buổi thảo luận ở lớp Nam</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> đã trình bày một ý tưởng rất thú vị</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> rằng bạn ấy vừa </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">«I invented an essentially new way of coding, which is impossible to decode , – Petya sai</span></span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">phát minh ra một cách mã hóa mới, </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">c</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">ó thể mã các thông tin, mà không ai có thể giải mã.</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> Cách mã hóa đó là:</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> <span lang="VI" style="display:none">– At the present time my coding works only for numbers. Let&#039;s consider an integer N, having t digits (in decimal notation ). Deleting the digits from this number by all possible ways, we will get some new number</span></span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">VớiV</span></span></span> <span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Với </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">một số nguyên N</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">,</span></span> <span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">x</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">oá các chữ số từ con số này bằng mọi cách có th</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">ể</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">, </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">ta</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> sẽ nhận được các số mới. <span style="display:none">Some way of deleting is to delete nothing.</span> Một số cách xóa mà </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">số mới </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">thu được </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">có giá trị bằng </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">số cũ </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">đó </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">là </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">khi</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">If we delete all digits, 0 is l</span></span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> ta xóa các chữ số 0 bên trái. <span style="display:none">Let&#039;s find the sum of all this numbers.</span> Hãy tìm tổng của tất cả các con số mới</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> thu được</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">.<span style="display:none">This sum is the code of N».</span> Tổng này </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">chính </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">là mã </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">hóa </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">của N. </span></span></span></span></span><br />
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">There were loud applauds.</span></span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Một bạn trong lớp đã có</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> ý kiến </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">&quot;Mình</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> nghĩ </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">cách mã hóa</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> của </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">cậu</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> trên máy tính sẽ thực hiện mất nhiều thời gian với số có nhiều chữ số, chẳng hạn số có 100 chữ số. <span style="display:none">Your life is not enough to code only one number, having 100 digits.</span> Không thể chờ để có một mã số cho số có 100 chữ số. <span style="display:none">Your algorithm can&#039;t be applied on practice ».</span> </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Các mã hóa này</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> của </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">bạn</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> không thể được áp dụng trên thực tế”. <span style="display:none">It was necessary to answer something. «No, no, and no.</span> </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Nam</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> đã trả lời </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">&quot;</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Không, </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">k</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">hông, không. <span style="display:none">Tomorrow I&#039;ll bring the realization of my algorithm, that will code the numbers, having 100 digits, in no more than 1 second», - that was the answer of Petya.</span> Ngày mai </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">mình</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> sẽ đưa ra chương trình thực hiện </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">cách mã hóa này</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">, và sẽ mã </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">hóa</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> cho số có 100 chữ số trong thời gian không quá 1 giây</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">&quot;</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> câu trả lời của </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Nam</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> được </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">cả lớp rất </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">hoan nghênh.<span style="display:none">Of course, Petya couldn&#039;t write such a program.</span> Bạn hãy giúp </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Nam</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> viết chương trình đó.</span></span></span></span></span><br />
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><b><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">&nbsp;Task.</span></span></span></b><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none"> Your program should input the integer N (1&lt;=N &lt;=10 <sup>100</sup> ) and determine the integer S – the code of N (using Petya&#039;s method of coding).</span></span></span><b><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Yêu cầu:</span></span></b><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> Cho số nguyên N (1 <u>&lt;</u> N <u>&lt;</u> 10<sup>100</sup></span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">)</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> và xác định số nguyên S </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">là</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> mã </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">hóa </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">của N </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">theo</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> phương pháp mã hóa </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">của Nam</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">. </span></span></span></span></span><br />
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><b><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">Input.</span></span></span></b><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none"> Input consists of one line, which contains one integer N. The left digit of N is not zero.</span></span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> <b>Dữ liệu</b></span></span><b><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">:</span></span></b><b> </b><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">V</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">ào</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> từ file văn bản <b>MAHOA.INP</b></span></span></span></span></span><br />
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><b><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">- </span></span></b><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Chỉ </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">một dòng duy</span></span> <span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">nhất </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">chứa một số nguyên N. </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">(</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">chữ số bên trái các chữ số của N<b><span style="display:none">Output.</span></b><span style="display:none"> You should output an integer S – the code of N. You should not output the leading zeroes.</span> </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">l</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">à khác 0</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">).</span></span></span></span></span><br />
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><b><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Kết quả:</span></span></b><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> Đưa ra </span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">file văn bản <b>MAHOA.OUT:</b> </span></span></span></span></span><br />
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">- Chỉ một số duy nhất là </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">số nguyên S</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> tìm được.</span></span> </span></span></span><br />
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><b><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">Example.</span></span></span></b><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> Ví dụ. </span></span></span></span></span><br />
&nbsp;
<table class="Table" style="width:240px; margin-left:48px; border:outset 2px" width="240">
	<tbody>
		<tr>
			<td style="padding:.100px .100px .100px .100px" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><a name="table02"></a><b><i><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">Input.Txt</span></span></span></i></b> <b><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">MAHOA.INP</span></span></b></span></span></span></td>
			<td style="padding:.100px .100px .100px .100px" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><i><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">Output.Txt</span></span></span></i><i><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">N</span></span></span></i><b><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">MAHOA.OUT</span></span></b></span></span></span></td>
		</tr>
		<tr>
			<td style="padding:.100px .100px .100px .100px" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">109</span></span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> 109 </span></span></span></span></span></td>
			<td style="padding:.100px .100px .100px .100px" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">157</span></span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> 157 </span></span></span></span></span></td>
		</tr>
	</tbody>
</table>
<br />
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><i><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Giải thích test ví dụ:</span></span></i></span></span></span><br />
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;N = 109. <span style="display:none">After deleting we get the numbers:</span> Sau khi xóa chúng t</span></span><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">a</span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> nhận được các số: </span></span></span></span></span><br />
&nbsp;
<table class="MsoTableGrid" style="margin-left:80px; border-collapse:collapse; border:none">
	<tbody>
		<tr>
			<td style="border-bottom:1px solid black; width:75px; padding:0cm 7px 0cm 7px; border-top:1px solid black; border-right:1px solid black; border-left:1px solid black" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">vị trí xóa</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:46px; padding:0cm 7px 0cm 7px; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top">&nbsp;</td>
			<td style="border-bottom:1px solid black; width:38px; padding:0cm 7px 0cm 7px; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">1</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:38px; padding:0cm 7px 0cm 7px; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">2</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:38px; padding:0cm 7px 0cm 7px; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">3</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:46px; padding:0cm 7px 0cm 7px; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">1, 2</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:46px; padding:0cm 7px 0cm 7px; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">1, 3</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:46px; padding:0cm 7px 0cm 7px; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">2, 3</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:71px; padding:0cm 7px 0cm 7px; border-top:1px solid black; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">1, 2, 3</span></span></span></span></span></td>
		</tr>
		<tr>
			<td style="border-bottom:1px solid black; width:75px; padding:0cm 7px 0cm 7px; border-top:none; border-right:1px solid black; border-left:1px solid black" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">số mới</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:46px; padding:0cm 7px 0cm 7px; border-top:none; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">109</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:38px; padding:0cm 7px 0cm 7px; border-top:none; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">09</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:38px; padding:0cm 7px 0cm 7px; border-top:none; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">19</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:38px; padding:0cm 7px 0cm 7px; border-top:none; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">10</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:46px; padding:0cm 7px 0cm 7px; border-top:none; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">9</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:46px; padding:0cm 7px 0cm 7px; border-top:none; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">0</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:46px; padding:0cm 7px 0cm 7px; border-top:none; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">1</span></span></span></span></span></td>
			<td style="border-bottom:1px solid black; width:71px; padding:0cm 7px 0cm 7px; border-top:none; border-right:1px solid black; border-left:none" valign="top"><span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">0</span></span></span></span></span></td>
		</tr>
	</tbody>
</table>
<span style="font-size:11pt"><span style="line-height:normal"><span style="font-family:Arial,sans-serif"><a name="table01"></a><span style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Tổng các số thu được: 109 + 09 + 19 + 10 + 9 + 0 + 1 + 0 = 157. </span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"><span style="display:none">So, the code of 109 is 157.</span></span></span><span lang="VI" style="font-size:12.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif"> Vì vậy, mã của 109 là 157.</span></span></span></span></span>

<h2><strong>Hướng dẫn giải.</strong></h2>
<span style="font-size:14pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Vì số N là số có đến 100 chữ số nên để tính kết quả cần xử lý số lớn.</span></span><br />
<span style="font-size:14pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Cách 1. Dùng tổ hợp xét sự xuất hiện của các số ở mỗi hàng sau đó tính tổng.</span></span><br />
<span style="font-size:14pt"><span style="font-family:&#039;Times New Roman&#039;,serif">Cách 2. Sử dụng công thức. Giả sử N có dạng a<sub>1</sub>a<sub>2</sub>.......a<sub>m</sub></span></span><br />
<span style="font-size:14.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Kết quả là: a<sub>1</sub>.2<sup>0</sup>.11<sup>m-1</sup> + a<sub>2</sub>.2</span></span><sup><span style="font-size:15.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">1</span></span></sup><span style="font-size:15.0pt"><span style="font-family:&#039;Times New Roman&#039;,serif">.11<sup>m-2</sup> + ......+ a<sub>m</sub>.2<sup>m-1</sup>.11<sup>0</sup> </span></span>

<h2>&nbsp;</h2>

<h2><strong>Code mẫu Pascal 1</strong></h2>

<pre>
<code class="language-python">const   fi=&#039;mahoa.inp&#039;;
        fo=&#039;mahoa.out&#039;;
type    mang=array&#91;0..201&#93; of longint;
        bignum=record
                 d:longint;
                 cs:mang;
               end;
var     f:text;
        n,m,i,j,k,l:longint;
        s:string;
        sl,res,a,b:bignum;
procedure doc;
begin
  assign(f,fi);
  reset(f);
  readln(f,s);
  close(f);
end;
procedure nhan(a:bignum;x:longint; var t:bignum);
var n,nho,i:longint;
    c:mang;
begin
  nho:=0;n:=a.d;
  fillchar(c,sizeof(c),0);
  for i:=1 to n do
    begin
      nho:=nho+a.cs&#91;i&#93;*x;
      c&#91;i&#93;:=nho mod 10;
      nho:=nho div 10;
    end;
  if nho&gt;0 then
    begin
      inc(n);
      c&#91;n&#93;:=nho;
    end;
  t.d:=n;t.cs:=c;
end;
procedure tong(a,b:bignum; var s:bignum);
var n,nho,i:longint;
    c:mang;
begin
  n:=a.d;
  if b.d&gt;n then n:=b.d;
  nho:=0;fillchar(c,sizeof(c),0);
  for i:=1 to n do
    begin
      nho:=nho+a.cs&#91;i&#93;+b.cs&#91;i&#93;;
      c&#91;i&#93;:=nho mod 10;
      nho:=nho div 10;
    end;
  if nho&gt;0 then
    begin
      inc(n);
      c&#91;n&#93;:=nho;
    end;
  S.d:=n;S.cs:=c;
end;
procedure lam;
begin
  n:=length(s);
  sl.d:=1;sl.cs&#91;1&#93;:=1;
  for i:=1 to n do
    begin
      nhan(res,11,a);
      nhan(sl,ord(s&#91;i&#93;)-48,b);
      nhan(sl,2,sl);
      tong(a,b,res);
    end;
end;
procedure ghi;
begin
  assign(f,fo);
  rewrite(f);
  with res do
    for i:=d downto 1 do write(f,cs&#91;i&#93;);
  close(f);
end;
begin
  doc;
  lam;
  ghi;
end.
</code></pre>

<h2>Code mẫu Pascal 2</h2>

<pre>
<code>const fip=&#039;mahoa.inp&#039;;
      fop=&#039;mahoa.out&#039;;
type bignum=string;
var  s: string;
     kq,tong1,tong2: bignum;
     c: array&#91;0..101,0..101&#93; of bignum;
procedure openf;
begin
     assign(input,fip); reset(input);
     assign(output,fop); rewrite(output);
end;
function cong(a,b: bignum): bignum;
var  c: bignum;
     i,x,y,carry,sum: longint;
begin
     while length(a)&lt;length(b) do a:=&#039;0&#039;+a;
     while length(b)&lt;length(a) do b:=&#039;0&#039;+b;
     carry:=0; c:=&#039;&#039;;
     for i:=length(a) downto 1 do
     begin
          x:=ord(a&#91;i&#93;)-48;
          y:=ord(b&#91;i&#93;)-48;
          sum:=x+y+carry;
          carry:=sum div 10;
          c:=chr(sum mod 10 + 48) + c;
     end;
     if carry&gt;0 then c:=&#039;1&#039;+c;
     cong:=c;
end;
function tiny_nhan(a: bignum; b: longint): bignum;
var  p: bignum;
     i,carry,x,tich: longint;
begin
     carry:=0; p:=&#039;&#039;;
     for i:=length(a) downto 1 do
     begin
          x:=ord(a&#91;i&#93;)-48;
          tich:=x*b+carry;
          carry:=tich div 10;
          p:=chr(tich mod 10 + 48) + p;
     end;
     if carry&gt;0 then p:=chr(carry+48)+p;
     tiny_nhan:=p;
end;
function huge_nhan(a,b: bignum): bignum;
var  p,temp: bignum;
     i,y,j: longint;
begin
     p:=&#039;0&#039;;
     for i:=length(b) downto 1 do
     begin
          y:=ord(b&#91;i&#93;)-48;
          temp:=tiny_nhan(a,y);
          for j:=1 to length(b)-i do temp:=temp+&#039;0&#039;;
          p:=cong(p,temp);
     end;
     while (p&#91;1&#93;=&#039;0&#039;) and (length(p)&gt;1) do delete(p,1,1);
     huge_nhan:=p;
end;
procedure init_tohop;
var  i,j: longint;
begin
     for j:=0 to 101 do c&#91;0,j&#93;:=&#039;1&#039;;
     for i:=0 to 101 do
          for j:=0 to 101 do if j&lt;i then c&#91;i,j&#93;:=&#039;0&#039;;
     c&#91;1,1&#93;:=&#039;1&#039;;
     for j:=2 to 100 do
          for i:=1 to j do c&#91;i,j&#93;:=cong(c&#91;i,j-1&#93;,c&#91;i-1,j-1&#93;);
end;
procedure xuly;
var  i,j,k,x,max: longint;
     temp1,temp2: bignum;
begin
     init_tohop;
     readln(s);
     kq:=&#039;0&#039;;
     for i:=1 to length(s) do
     begin
          tong1:=&#039;0&#039;;
          x:=ord(s&#91;i&#93;)-48;
          max:=length(s)-i;
          for j:=0 to max do
          begin
               temp1:=tiny_nhan(c&#91;j,max&#93;,x);
               for k:=1 to j do temp1:=temp1+&#039;0&#039;;
               tong1:=cong(temp1,tong1);
          end;
          tong2:=&#039;0&#039;;
          for j:=1 to i-1 do
          begin
               tong2:=cong(c&#91;j,i-1&#93;,tong2);
          end;
          tong2:=cong(tong2,&#039;1&#039;);
          temp2:=huge_nhan(tong1,tong2);
          kq:=cong(kq,temp2);
     end;
     writeln(kq);
end;
BEGIN
     openf;
     xuly;
END.
</code></pre>
&nbsp;​Hai code mẫu Pascal ở trên chắc không ít bạn đọc sẽ khó hiểu, để hiểu được phần nào thì các bạn cần tìm hiểu TỔ HỢP và các xử lý cộng SỐ LƠN trong pascal.

<h2><strong>Một số cách giải quyết bằng Python.</strong></h2>

<h3><strong>Cách 1: Sử dụng cách duyệt qua tất cả các số mới được tao ra. (Không tối ưu - chỉ để tham khảo)</strong></h3>
Để giải bài tập này, bạn có thể sử dụng một vòng lặp để duyệt qua các số mới được tạo ra từ cách xóa chữ số của số nguyên a ban đầu. Sau đó, bạn có thể tính tổng của tất cả các số mới này để tìm ra mã hóa của số nguyên a. Tuy nhiên cách này không tối ưu, tôi chỉ trình bày để các bạn tham khảo. Với cách này khi duyệt qua tất cả các số mới được tạo ra thì sẽ có rất nhiều số. Ví dụ số 123, có 3 chữ số, thì khi xóa theo cách mã hóa trên thì sẽ có tới 2<sup>3</sup>&nbsp;-1 = 7 số được tạo ra: 1, 2, 3, 12, 13, 23, 123. Như vậy nếu số a có 100 chữ số thì sẽ có 2<sup>100</sup>&nbsp;- 1 số mới được tạo ra. Do đó cách này sẽ không tối ưu bằng cách sử dụng TỔ HỢP như 2 code mẫu Pascal trên. Các bạn chỉ tham khảo thôi nhé.

<pre>
<code class="language-python">with open(&#039;mahoa.inp&#039;,&#039;r&#039;) as f:
    a = f.readline().rstrip()
n = len(a) # Độ dài của a
s = 0 # Khởi tạo tổng các số mới là 0

# Duyệt qua các số mới được tạo ra từ cách xóa các chữ số của a
for i in range(1, 2**n):
    num = &#039;&#039;
    for j in range(n):
        if i &amp; (1 &lt;&lt; j):
            num += a&#91;j&#93;
    s += int(num)

with open(&#039;mahoa.out&#039;,&#039;w&#039;) as f:
    f.write(str(s))</code></pre>
<br />
Nhìn code thì các bạn cũng hiểu là không tối ưu rôi ha. Code này chỉ chạy đến test 3, sang test 4 là chạy quá 1 giây. Trong ví dụ trên chắc không ít bạn thắc mắc&nbsp; <code>if i &amp; (1 &lt;&lt; j):&nbsp;</code>Ở đây, chúng ta sử dụng biểu thức&nbsp;<code>&nbsp;i &amp; (1 &lt;&lt; j)</code>&nbsp;để kiểm tra xem bit thứ j của số mới i có bật hay không. Cụ thể, biểu thức này sẽ trả về một số có giá trị bằng 0 hoặc 2^j tùy thuộc vào bit thứ j của i có bật hay không. Nếu bit này bật, thì giá trị trả về sẽ là 2^j; ngược lại, nếu bit này tắt, thì giá trị trả về sẽ là 0.

<p>Ví dụ: Nếu i = 5 (101 trong hệ nhị phân) và j = 1, thì biểu thức&nbsp;<code>i &amp; (1 &lt;&lt; j)</code>&nbsp;sẽ trả về giá trị 4 (100 trong hệ nhị phân), vì bit thứ 1 của i là 0.</p>

<p>Trong ví dụ của chúng ta, chúng ta sử dụng biểu thức này để kiểm tra xem chữ số nào của số nguyên a ban đầu sẽ được giữ lại trong số mới được tạo ra từ cách xóa chữ số của a.</p>

<h3>Trong cách không tối ưu, các bạn có thể tham khảo thêm cách sử dụng hàm sau, trong hàm mình đã giải thích rồi ha:</h3>

<pre>
<code class="language-python">def tao_so_moi(n, start):
    &quot;&quot;&quot;
    Tạo số mới từ số n, bắt đầu từ vị trí start đến hết số.
    Các số mới tạo ra đưa vào danh sách new_numbers.
    &quot;&quot;&quot;
    #Nếu số n chỉ còn lại 1 chữ số thì quay lại.
    if len(n) == 1:
        return

    #Loại bỏ tất cả các chữ số từ vị trí start và thử tìm tất cả các số mới rồi thêm chúng vào list.
    for i in range(start, len(n)):
        new_num = n&#91;:i&#93; + n&#91;i+1:&#93;
        new_numbers.append(int(new_num))
        tao_so_moi(new_num, i)

n=&#039;109&#039;
new_numbers = &#91;int(n)&#93;
tao_so_moi(n, 0)
print(sum(new_numbers))</code></pre>
&nbsp;

<h3><strong>Cách 2: Sử dụng công thức toán học.</strong></h3>

<pre>
<code class="language-python">with open(&#039;mahoa.inp&#039;,&#039;r&#039;) as f:
    n = f.readline().rstrip()
m = len(n)
res = 0
for i in range(m):
    res += int(n&#91;i&#93;)*2**i*11**(m-1-i)
with open(&#039;mahoa.out&#039;,&#039;w&#039;) as f:
    f.write(str(res))</code></pre>
		</div>
				<div id="author">
						<p>
				<strong>Tác giả:</strong>
				<a href="https://baitaponha.com/author/admin/">admin</a>
			</p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://baitaponha.com/savefile/giai-de-tin-hoc/ma-hoa-cau-4-de-thi-hsg-tin-12-nghe-an-nam-2013-2014-44.html" title="Mã Hóa | Câu 4 - Đề thi HSG tin 12 Nghệ An | Năm 2013-2014">https://baitaponha.com/savefile/giai-de-tin-hoc/ma-hoa-cau-4-de-thi-hsg-tin-12-nghe-an-nam-2013-2014-44.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; BÀI TẬP Ở NHÀ
		</div>
		<div id="contact">
			<a href="mailto:ducluu80@gmail.com">ducluu80@gmail.com</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://baitaponha.com/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
<div id="run_cronjobs" style="visibility:hidden;display:none;"><img alt="cron" src="/index.php?second=cronjobs&amp;p=b6DF2pKG" width="1" height="1" /></div>
<script src="https://baitaponha.com/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="btol",nv_check_pass_mstime=21538000,nv_area_admin=0,nv_safemode=0,theme_responsive=0,nv_recaptcha_ver=2,nv_recaptcha_sitekey="",nv_recaptcha_type="image",XSSsanitize=1;</script>
<script src="https://baitaponha.com/assets/js/language/vi.js"></script>
<script src="https://baitaponha.com/assets/js/DOMPurify/purify3.js"></script>
<script src="https://baitaponha.com/assets/js/global.js"></script>
<script src="https://baitaponha.com/assets/js/site.js"></script>
<script src="https://baitaponha.com/themes/default/js/news.js"></script>
<script src="https://baitaponha.com/assets/js/jquery/jquery.cookie.js"></script>
<script src="https://baitaponha.com/themes/egov/js/main.js"></script>
<script src="https://baitaponha.com/themes/egov/js/custom.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4JBZJ8SEPL"></script>
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag('js',new Date);gtag('config','G-4JBZJ8SEPL');</script>
<script src="https://baitaponha.com/themes/egov/js/bootstrap.min.js"></script>
</body>
</html>