{"id":204,"date":"2026-01-08T11:17:59","date_gmt":"2026-01-08T03:17:59","guid":{"rendered":"https:\/\/jiangqvweihuan.cn\/?p=204"},"modified":"2026-04-26T19:35:26","modified_gmt":"2026-04-26T11:35:26","slug":"%e5%bf%ab%e9%80%9f%e5%b9%82","status":"publish","type":"post","link":"https:\/\/jiangqvweihuan.cn\/index.php\/2026\/01\/08\/%e5%bf%ab%e9%80%9f%e5%b9%82\/","title":{"rendered":"\u7b97\u6cd5\u5fc3\u4f20\u00b7\u5feb\u901f\u5e42"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4f4d\u8fd0\u7b97\u6cd5\u5219<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u4f4d\u8fd0\u7b97\u6982\u8ff0<\/h3>\n\n\n\n<p>\u5728\u73b0\u4ee3\u8ba1\u7b97\u673a\u4e2d\uff0c\u6240\u6709\u6570\u636e\u90fd\u4ee5<strong>\u4e8c\u8fdb\u5236<\/strong>\u5f62\u5f0f\u5b58\u50a8\uff0c\u5373 0 \u548c 1 \u4e24\u79cd\u72b6\u6001\u3002\u8ba1\u7b97\u673a\u5bf9\u4e8c\u8fdb\u5236\u6570\u636e\u8fdb\u884c\u7684\u8fd0\u7b97\uff08\u5982\u52a0\u3001\u51cf\u3001\u4e58\u3001\u9664\uff09\u88ab\u79f0\u4e3a\u4f4d\u8fd0\u7b97\uff0c\u5373\u5bf9\u4e8c\u8fdb\u5236\u6570\u7684\u6bcf\u4e00\u4f4d\u8fdb\u884c\u64cd\u4f5c\u7684\u8fd0\u7b97\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a = 35;\nint b = 47;\nint c = a + b;<\/code><\/pre>\n\n\n\n<p>\u8ba1\u7b97\u673a\u4f1a\u5c06\u8fd9\u4e24\u4e2a\u6574\u6570\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u5f62\u5f0f\uff0c\u7136\u540e\u8fdb\u884c\u52a0\u6cd5\u8fd0\u7b97\uff1a<\/p>\n\n\n<p>35:  0010 0011<br \/>\n47:  0010 1111<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n82:  0101 0010<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u4e0e\u76f4\u63a5\u4f7f\u7528&nbsp;+\u3001-\u3001*\u3001\/&nbsp;\u8fd0\u7b97\u7b26\u76f8\u6bd4\uff0c\u5408\u7406\u8fd0\u7528\u4f4d\u8fd0\u7b97\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u4ee3\u7801\u5728\u673a\u5668\u4e0a\u7684\u6267\u884c\u6548\u7387\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.\u4f4d\u8fd0\u7b97\u6982\u89c8<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-blush-light-purple-gradient-background has-background\"><thead><tr><th>\u7b26\u53f7<\/th><th>\u63cf\u8ff0<\/th><th>\u8fd0\u7b97\u89c4\u5219<\/th><\/tr><\/thead><tbody><tr><td>&amp;<\/td><td>\u4e0e<\/td><td>\u4e24\u4e2a\u4f4d\u90fd\u4e3a1\u65f6\uff0c\u7ed3\u679c\u624d\u4e3a1<\/td><\/tr><tr><td>|<\/td><td>\u6216<\/td><td>\u4e24\u4e2a\u4f4d\u90fd\u4e3a0\u65f6\uff0c\u7ed3\u679c\u624d\u4e3a0<\/td><\/tr><tr><td>^<\/td><td>\u5f02\u6216<\/td><td>\u4e24\u4e2a\u4f4d\u76f8\u540c\u4e3a0\uff0c\u76f8\u5f02\u4e3a1<\/td><\/tr><tr><td>~<\/td><td>\u53d6\u53cd<\/td><td>0\u53d81\uff0c1\u53d80<\/td><\/tr><tr><td>&lt;&lt;<\/td><td>\u5de6\u79fb<\/td><td>\u5404\u4e8c\u8fdb\u4f4d\u5168\u90e8\u5de6\u79fb\u82e5\u5e72\u4f4d\uff0c\u9ad8\u4f4d\u4e22\u5f03\uff0c\u4f4e\u4f4d\u88650<\/td><\/tr><tr><td>&gt;&gt;<\/td><td>\u53f3\u79fb<\/td><td>\u5404\u4e8c\u8fdb\u4f4d\u5168\u90e8\u53f3\u79fb\u82e5\u5e72\u4f4d\uff0c\u9ad8\u4f4d\u88650\u6216\u7b26\u53f7\u4f4d\u8865\u9f50<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">2.1 \u6309\u4f4d\u4e0e\u8fd0\u7b97\u7b26\uff08&amp;\uff09<\/h4>\n\n\n\n<p><strong>\u5b9a\u4e49<\/strong>\uff1a\u5bf9\u53c2\u4e0e\u8fd0\u7b97\u7684\u4e24\u4e2a\u6570\u636e\u7684\u4e8c\u8fdb\u5236\u4f4d\u8fdb\u884c&#8221;\u4e0e&#8221;\u8fd0\u7b97\u3002<\/p>\n\n\n\n<p><strong>\u8fd0\u7b97\u89c4\u5219<\/strong>\uff1a<\/p>\n\n\n<p>0 &#038; 0 = 0<br \/>\n0 &#038; 1 = 0<br \/>\n1 &#038; 0 = 0<br \/>\n1 &#038; 1 = 1<\/p>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong>\uff1a\u53ea\u6709\u4e24\u4f4d\u540c\u65f6\u4e3a1\u65f6\uff0c\u7ed3\u679c\u624d\u4e3a1\uff0c\u5426\u5219\u7ed3\u679c\u4e3a0\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a3 &amp; 5&nbsp;\u5373&nbsp;0000 0011 &amp; 0000 0101 = 0000 0001\uff0c\u56e0\u6b64&nbsp;3 &amp; 5&nbsp;\u7684\u503c\u4e3a1\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u8d1f\u6570\u6309\u8865\u7801\u5f62\u5f0f\u53c2\u4e0e\u6309\u4f4d\u4e0e\u8fd0\u7b97\u3002<\/p>\n\n\n\n<p><strong>\u7528\u9014<\/strong>\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6e05\u96f6<\/strong>\uff1a\u5982\u679c\u60f3\u5c06\u4e00\u4e2a\u5355\u5143\u6e05\u96f6\uff0c\u53ea\u8981\u4e0e\u4e00\u4e2a\u5404\u4f4d\u90fd\u4e3a\u96f6\u7684\u6570\u503c\u76f8\u4e0e\uff0c\u7ed3\u679c\u4e3a\u96f6\u3002<\/li>\n\n\n\n<li><strong>\u53d6\u4e00\u4e2a\u6570\u7684\u6307\u5b9a\u4f4d<\/strong>\uff1a\u4f8b\u5982\uff0c\u53d6\u6570&nbsp;X = 1010 1110&nbsp;\u7684\u4f4e4\u4f4d\uff0c\u53ea\u9700\u53e6\u627e\u4e00\u4e2a\u6570&nbsp;Y = 0000 1111\uff0c\u7136\u540e&nbsp;X &amp; Y = 0000 1110&nbsp;\u5373\u53ef\u5f97\u5230&nbsp;X&nbsp;\u7684\u6307\u5b9a\u4f4d\u3002<\/li>\n\n\n\n<li><strong>\u5224\u65ad\u5947\u5076<\/strong>\uff1a\u901a\u8fc7\u5224\u65ad\u6700\u672a\u4f4d\u662f0\u8fd8\u662f1\u6765\u51b3\u5b9a\u5947\u5076\uff0c\u53ef\u4ee5\u7528&nbsp;if ((a &amp; 1) == 0)&nbsp;\u4ee3\u66ff&nbsp;if (a % 2 == 0)&nbsp;\u6765\u5224\u65ad&nbsp;a&nbsp;\u662f\u5426\u4e3a\u5076\u6570\u3002<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">2.2 \u6309\u4f4d\u6216\u8fd0\u7b97\u7b26\uff08|\uff09<\/h4>\n\n\n\n<p><strong>\u5b9a\u4e49<\/strong>\uff1a\u5bf9\u53c2\u4e0e\u8fd0\u7b97\u7684\u4e24\u4e2a\u5bf9\u8c61\u7684\u4e8c\u8fdb\u5236\u4f4d\u8fdb\u884c&#8221;\u6216&#8221;\u8fd0\u7b97\u3002<\/p>\n\n\n\n<p><strong>\u8fd0\u7b97\u89c4\u5219<\/strong>\uff1a<\/p>\n\n\n<p>0 | 0 = 0<br \/>\n0 | 1 = 1<br \/>\n1 | 0 = 1<br \/>\n1 | 1 = 1<\/p>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong>\uff1a\u53ea\u8981\u6709\u4e00\u4e2a\u4e3a1\uff0c\u5176\u503c\u4e3a1\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a3 | 5&nbsp;\u5373&nbsp;0000 0011 | 0000 0101 = 0000 0111\uff0c\u56e0\u6b64&nbsp;3 | 5&nbsp;\u7684\u503c\u4e3a7\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u8d1f\u6570\u6309\u8865\u7801\u5f62\u5f0f\u53c2\u4e0e\u6309\u4f4d\u6216\u8fd0\u7b97\u3002<\/p>\n\n\n\n<p><strong>\u7528\u9014<\/strong>\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u8bbe\u7f6e\u67d0\u4e9b\u4f4d\u4e3a1<\/strong>\uff1a\u4f8b\u5982\uff0c\u5c06\u6570&nbsp;X = 1010 1110&nbsp;\u7684\u4f4e4\u4f4d\u8bbe\u7f6e\u4e3a1\uff0c\u53ea\u9700\u53e6\u627e\u4e00\u4e2a\u6570&nbsp;Y = 0000 1111\uff0c\u7136\u540e&nbsp;X | Y = 1010 1111&nbsp;\u5373\u53ef\u5f97\u5230\u3002<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">2.3 \u5f02\u6216\u8fd0\u7b97\u7b26\uff08^\uff09<\/h4>\n\n\n\n<p><strong>\u5b9a\u4e49<\/strong>\uff1a\u5bf9\u53c2\u4e0e\u8fd0\u7b97\u7684\u4e24\u4e2a\u6570\u636e\u7684\u4e8c\u8fdb\u5236\u4f4d\u8fdb\u884c&#8221;\u5f02\u6216&#8221;\u8fd0\u7b97\u3002<\/p>\n\n\n\n<p><strong>\u8fd0\u7b97\u89c4\u5219<\/strong>\uff1a<\/p>\n\n\n<p>0 ^ 0 = 0<br \/>\n0 ^ 1 = 1<br \/>\n1 ^ 0 = 1<br \/>\n1 ^ 1 = 0<\/p>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong>\uff1a\u76f8\u5e94\u4f4d\u76f8\u540c\u4e3a0\uff0c\u76f8\u5f02\u4e3a1\u3002<\/p>\n\n\n\n<p><strong>\u6027\u8d28<\/strong>\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4ea4\u6362\u5f8b<\/li>\n\n\n\n<li>\u7ed3\u5408\u5f8b\uff1a&nbsp;(a ^ b) ^ c == a ^ (b ^ c)<\/li>\n\n\n\n<li>\u5bf9\u4e8e\u4efb\u4f55\u6570&nbsp;x\uff0c\u90fd\u6709&nbsp;x ^ x = 0\uff0cx ^ 0 = x<\/li>\n\n\n\n<li>\u81ea\u53cd\u6027\uff1aa ^ b ^ b = a ^ 0 = a<\/li>\n<\/ol>\n\n\n\n<p><strong>\u7528\u9014<\/strong>\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7ffb\u8f6c\u6307\u5b9a\u4f4d<\/strong>\uff1a\u4f8b\u5982\uff0c\u5c06\u6570&nbsp;X = 1010 1110&nbsp;\u7684\u4f4e4\u4f4d\u7ffb\u8f6c\uff0c\u53ea\u9700\u53e6\u627e\u4e00\u4e2a\u6570&nbsp;Y = 0000 1111\uff0c\u7136\u540e&nbsp;X ^ Y = 1010 0001&nbsp;\u5373\u53ef\u5f97\u5230\u3002<\/li>\n\n\n\n<li><strong>\u4e0e0\u76f8\u5f02\u6216\u503c\u4e0d\u53d8<\/strong>\uff1a\u4f8b\u5982&nbsp;1010 1110 ^ 0000 0000 = 1010 1110<\/li>\n\n\n\n<li><strong>\u4ea4\u6362\u4e24\u4e2a\u6570<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>void Swap(int &amp;a, int &amp;b) {\n    if (a != b) {\n        a ^= b;\n        b ^= a;\n        a ^= b;\n    }\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.4 \u53d6\u53cd\u8fd0\u7b97\u7b26\uff08~\uff09<\/h4>\n\n\n\n<p><strong>\u5b9a\u4e49<\/strong>\uff1a\u5bf9\u53c2\u4e0e\u8fd0\u7b97\u7684\u4e00\u4e2a\u6570\u636e\u7684\u4e8c\u8fdb\u5236\u4f4d\u8fdb\u884c&#8221;\u53d6\u53cd&#8221;\u8fd0\u7b97\u3002<\/p>\n\n\n\n<p><strong>\u8fd0\u7b97\u89c4\u5219<\/strong>\uff1a<\/p>\n\n\n<p>~1 = 1111 1110<br \/>\n~0 = 1111 1111<br \/>\n\u5373<br \/>\n~1 = -2<br \/>\n~0 = -1<\/p>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong>\uff1a\u5c06 0 \u53d8 1\uff0c1 \u53d8 0\u3002<\/p>\n\n\n\n<p><strong>\u7528\u9014<\/strong>\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4f7f\u4e00\u4e2a\u6570\u7684\u6700\u4f4e\u4f4d\u4e3a\u96f6<\/strong>\uff1a\u4f8b\u5982\uff0c\u4f7f&nbsp;a&nbsp;\u7684\u6700\u4f4e\u4f4d\u4e3a0\uff0c\u53ef\u4ee5\u8868\u793a\u4e3a\uff1aa &amp; ~1\u3002~1&nbsp;\u7684\u503c\u4e3a&nbsp;1111 1111 1111 1110\uff0c\u518d\u6309&#8221;\u4e0e&#8221;\u8fd0\u7b97\uff0c\u6700\u4f4e\u4f4d\u4e00\u5b9a\u4e3a0\u3002<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">2.5 \u5de6\u53f3\u79fb\u8fd0\u7b97\u7b26\uff08&lt;&lt; \u548c &gt;&gt;\uff09<\/h4>\n\n\n\n<p><strong>\u5b9a\u4e49<\/strong>\uff1a\u5c06\u4e00\u4e2a\u8fd0\u7b97\u5bf9\u8c61\u7684\u5404\u4e8c\u8fdb\u5236\u4f4d\u5168\u90e8\u5de6\u79fb\u82e5\u5e72\u4f4d\uff0c\u9ad8\u4f4d\u4e22\u5f03\uff0c\u4f4e\u4f4d\u88650\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u8bbe&nbsp;a = 1010 1110\uff0ca = a &lt;&lt; 2&nbsp;\u5c06&nbsp;a&nbsp;\u7684\u4e8c\u8fdb\u5236\u4f4d\u5de6\u79fb2\u4f4d\u3001\u53f3\u88650\uff0c\u5373\u5f97&nbsp;a = 1011 1000\u3002<\/p>\n\n\n\n<p>\u82e5\u5de6\u79fb\u65f6\u820d\u5f03\u7684\u9ad8\u4f4d\u4e0d\u5305\u542b1\uff0c\u5219\u6bcf\u5de6\u79fb\u4e00\u4f4d\uff0c\u76f8\u5f53\u4e8e\u8be5\u6570\u4e58\u4ee52\u3002<\/p>\n\n\n\n<p>\u5c06\u4e00\u4e2a\u6570\u7684\u5404\u4e8c\u8fdb\u5236\u4f4d\u5168\u90e8\u53f3\u79fb\u82e5\u5e72\u4f4d\uff0c\u9ad8\u4f4d\u88650\u6216\u8865\u7b26\u53f7\u4f4d\uff0c\u53f3\u8fb9\u4e22\u5f03\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0ca = a &gt;&gt; 2&nbsp;\u5c06&nbsp;a&nbsp;\u7684\u4e8c\u8fdb\u5236\u4f4d\u53f3\u79fb2\u4f4d\uff0c\u5de6\u88650 \u6216\u8865\u7b26\u53f7\u4f4d\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6570\u7684\u6b63\u8d1f\u3002<\/p>\n\n\n\n<p>\u64cd\u4f5c\u6570\u6bcf\u53f3\u79fb\u4e00\u4f4d\uff0c\u76f8\u5f53\u4e8e\u8be5\u6570\u9664\u4ee52\u3002<\/p>\n\n\n\n<p><strong>\u7528\u9014\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5feb\u901f\u4e58\u9664<\/strong>\uff1a\u5de6\u79fb\u76f8\u5f53\u4e8e\u4e58\u4ee52\u7684\u5e42\uff0c\u53f3\u79fb\u76f8\u5f53\u4e8e\u9664\u4ee52\u7684\u5e42<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>int a = 10;\nint b = a &lt;&lt; 2; \/\/ \u76f8\u5f53\u4e8e a * 4 = 40\nint c = a &gt;&gt; 1; \/\/ \u76f8\u5f53\u4e8e a \/ 2 = 5<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.6 \u590d\u5408\u8d4b\u503c\u8fd0\u7b97\u7b26<\/h4>\n\n\n\n<p>\u4f4d\u8fd0\u7b97\u7b26\u4e0e\u8d4b\u503c\u8fd0\u7b97\u7b26\u7ed3\u5408\uff0c\u7ec4\u6210\u65b0\u7684\u590d\u5408\u8d4b\u503c\u8fd0\u7b97\u7b26\uff0c\u5b83\u4eec\u662f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&amp;=&nbsp;\u4f8b\uff1aa &amp;= b&nbsp;\u76f8\u5f53\u4e8e&nbsp;a = a &amp; b<\/li>\n\n\n\n<li>|=&nbsp;\u4f8b\uff1aa |= b&nbsp;\u76f8\u5f53\u4e8e&nbsp;a = a | b<\/li>\n\n\n\n<li>&gt;&gt;=&nbsp;\u4f8b\uff1aa &gt;&gt;= b&nbsp;\u76f8\u5f53\u4e8e&nbsp;a = a &gt;&gt; b<\/li>\n\n\n\n<li>&lt;&lt;=&nbsp;\u4f8b\uff1aa &lt;&lt;= b&nbsp;\u76f8\u5f53\u4e8e&nbsp;a = a &lt;&lt; b<\/li>\n\n\n\n<li>^=&nbsp;\u4f8b\uff1aa ^= b&nbsp;\u76f8\u5f53\u4e8e&nbsp;a = a ^ b<\/li>\n<\/ul>\n\n\n\n<p>\u8fd0\u7b97\u89c4\u5219\u4e0e\u524d\u8ff0\u7684\u590d\u5408\u8d4b\u503c\u8fd0\u7b97\u7b26\u7684\u8fd0\u7b97\u89c4\u5219\u76f8\u4f3c\u3002<\/p>\n\n\n\n<p><strong>\u4e0d\u540c\u957f\u5ea6\u7684\u6570\u636e\u8fdb\u884c\u4f4d\u8fd0\u7b97<\/strong>\uff1a<\/p>\n\n\n\n<p>\u5982\u679c\u4e24\u4e2a\u4e0d\u540c\u957f\u5ea6\u7684\u6570\u636e\u8fdb\u884c\u4f4d\u8fd0\u7b97\uff0c\u7cfb\u7edf\u4f1a\u5c06\u4e8c\u8005\u6309\u53f3\u7aef\u5bf9\u9f50\uff0c\u7136\u540e\u8fdb\u884c\u4f4d\u8fd0\u7b97\u3002<\/p>\n\n\n\n<p>\u4ee5&#8221;\u4e0e\u8fd0\u7b97&#8221;\u4e3a\u4f8b\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u5728 C++ \u4e2d\uff0c\u5f53\u6574\u578b\u7c7b\u578b\u5c0f\u4e8e&nbsp;int&nbsp;\u65f6\uff0c\u8fd0\u7b97\u524d\u4f1a\u5148\u8fdb\u884c\u6574\u578b\u63d0\u5347\u3002\u5bf9\u4e8e\u4f4d\u8fd0\u7b97\uff0c\u5f53\u4e24\u4e2a\u4e0d\u540c\u7c7b\u578b\u7684\u6574\u6570\u8fdb\u884c\u8fd0\u7b97\u65f6\uff0c\u8f83\u5c0f\u7c7b\u578b\u4f1a\u63d0\u5347\u5230\u8f83\u5927\u7c7b\u578b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u6709\u7b26\u53f7\u6e90\u7c7b\u578b\u4e3a\u6b63\u6570\u6216\u96f6\uff1a\u9ad8\u4f4d\u8865 0\uff08\u96f6\u6269\u5c55\uff09<\/li>\n\n\n\n<li>\u5982\u679c\u6709\u7b26\u53f7\u6e90\u7c7b\u578b\u4e3a\u8d1f\u6570\uff1a\u9ad8\u4f4d\u8865\u7b26\u53f7\u4f4d\uff08\u7b26\u53f7\u6269\u5c55\uff09<\/li>\n\n\n\n<li>\u5982\u679c\u6e90\u7c7b\u578b\u4e3a\u65e0\u7b26\u53f7\u7c7b\u578b\uff1a\u9ad8\u4f4d\u8865 0\uff08\u96f6\u6269\u5c55\uff09<\/li>\n<\/ul>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int32_t a = 123;\nuint16_t b = 1;\nint32_t result = a &amp; static_cast&lt;int32_t&gt;(b);  \/\/ b \u88ab\u63d0\u5347\uff0c\u9ad8\u4f4d\u88650<\/code><\/pre>\n\n\n\n<p>\u4e0b\u9762\u7ed9\u51fa\u6309\u4f4d\u5f02\u6216\u7684\u51e0\u4e2a\u80fd\u5f00\u9614\u601d\u7ef4\u7684\u9898\u76ee\uff1a<br><a href=\"https:\/\/ac.nowcoder.com\/acm\/contest\/85639\/D\">https:\/\/ac.nowcoder.com\/acm\/contest\/85639\/D<\/a><br><a href=\"https:\/\/codeforces.com\/contest\/2225\/problem\/D\">https:\/\/codeforces.com\/contest\/2225\/problem\/D<\/a><\/p>\n\n\n\n<p>\u5b66\u4f1a\u4e86\u524d\u7f6e\u77e5\u8bc6\uff0c\u6211\u4eec\u5c31\u80fd\u8fc5\u901f\u7406\u89e3\u6b63\u7bc7\u2014\u2014\u5feb\u901f\u5e42\u7b97\u6cd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u5feb\u901f\u5e42<\/h2>\n\n\n\n<p><strong>\u5feb\u901f\u5e42<\/strong>\uff08fast exponentiation\uff09\uff0c\u4e5f\u79f0&nbsp;<strong>\u4e8c\u8fdb\u5236\u53d6\u5e42<\/strong>\uff08binary exponentiation\uff09\u6216&nbsp;<strong>\u5e73\u65b9\u53d6\u5e42\u6cd5<\/strong>\uff08exponentiation by squaring\uff09\uff0c\u662f\u4e00\u4e2a\u5728&nbsp;O(log\u2061\ud835\udc5b)\u7684\u65f6\u95f4\u5185\u8ba1\u7b97&nbsp;<strong><math data-latex=\"a^n\"><semantics><msup><mi>a<\/mi><mi>n<\/mi><\/msup><annotation encoding=\"application\/x-tex\">a^n<\/annotation><\/semantics><\/math><\/strong>\u7684\u5c0f\u6280\u5de7\uff0c\u800c\u66b4\u529b\u7684\u8ba1\u7b97\u9700\u8981&nbsp;O(\ud835\udc5b)\u7684\u65f6\u95f4\uff0e<\/p>\n\n\n\n<p>\u5feb\u901f\u5e42\u7b97\u6cd5\u7684\u6838\u5fc3\u601d\u60f3\u5c31\u662f\u6bcf\u4e00\u6b65\u90fd\u628a\u6307\u6570\u5206\u6210\u4e24\u534a\uff0c\u800c\u76f8\u5e94\u7684\u5e95\u6570\u505a\u5e73\u65b9\u8fd0\u7b97\u3002\u8fd9\u6837\u4e0d\u4ec5\u80fd\u628a\u975e\u5e38\u5927\u7684\u6307\u6570\u7ed9\u4e0d\u65ad\u53d8\u5c0f\uff0c\u6240\u9700\u8981\u6267\u884c\u7684\u5faa\u73af\u6b21\u6570\u4e5f\u53d8\u5c0f\uff0c\u800c\u6700\u540e\u8868\u793a\u7684\u7ed3\u679c\u5374\u4e00\u76f4\u4e0d\u4f1a\u53d8\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\u8ba1\u7b97<strong><math data-latex=\"3^{10}\"><semantics><msup><mn>3<\/mn><mn>10<\/mn><\/msup><annotation encoding=\"application\/x-tex\">3^{10}<\/annotation><\/semantics><\/math><\/strong>\u6211\u4eec\u53ef\u4ee5\u8868\u793a\u4e3a<\/p>\n\n\n\n<p><math data-latex=\"3^{10} = \"><semantics><mrow><msup><mn>3<\/mn><mn>10<\/mn><\/msup><mo>=<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">3^{10} = <\/annotation><\/semantics><\/math><math data-latex=\"(3^2)^5 = 3^2 * (3^2)^4 = 9 * 81^2\"><semantics><mrow><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mn>3<\/mn><mn>2<\/mn><\/msup><msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mn>5<\/mn><\/msup><mo>=<\/mo><msup><mn>3<\/mn><mn>2<\/mn><\/msup><mo>\u2217<\/mo><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mn>3<\/mn><mn>2<\/mn><\/msup><msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mn>4<\/mn><\/msup><mo>=<\/mo><mn>9<\/mn><mo>\u2217<\/mo><msup><mn>81<\/mn><mn>2<\/mn><\/msup><\/mrow><annotation encoding=\"application\/x-tex\">(3^2)^5 = 3^2 * (3^2)^4 = 9 * 81^2<\/annotation><\/semantics><\/math><\/p>\n\n\n\n<p>\u4e0d\u96be\u53d1\u73b0<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5982\u679c\u6307\u6570\u662f\u662f\u5076\u6570\uff0c\u90a3\u4e48\u6307\u6570\u9664\u4ee52\uff0c\u5e95\u6570\u5e73\u65b9\uff0c\u524d\u540e\u7684\u503c\u76f8\u7b49\u3002\uff08<math data-latex=\"res*3^{10}=res*(3^2)^5\"><semantics><mrow><mi>r<\/mi><mi>e<\/mi><mi>s<\/mi><mo>\u2217<\/mo><msup><mn>3<\/mn><mn>10<\/mn><\/msup><mo>=<\/mo><mi>r<\/mi><mi>e<\/mi><mi>s<\/mi><mo>\u2217<\/mo><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mn>3<\/mn><mn>2<\/mn><\/msup><msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mn>5<\/mn><\/msup><\/mrow><annotation encoding=\"application\/x-tex\">res*3^{10}=res*(3^2)^5<\/annotation><\/semantics><\/math>\uff09<\/li>\n\n\n\n<li>\u5982\u679c\u6307\u6570\u662f\u5947\u6570\uff0c\u5c06ans*=\u5e95\u6570\uff0c\u518d\u6307\u6570\u9664\u4ee52\uff0c\u5e95\u6570\u5e73\u65b9\uff0c\u524d\u540e\u503c\u76f8\u540c\u3002\uff08<math data-latex=\"res*9^5=res*9*81^2\"><semantics><mrow><mi>r<\/mi><mi>e<\/mi><mi>s<\/mi><mo>\u2217<\/mo><msup><mn>9<\/mn><mn>5<\/mn><\/msup><mo>=<\/mo><mi>r<\/mi><mi>e<\/mi><mi>s<\/mi><mo>\u2217<\/mo><mn>9<\/mn><mo>\u2217<\/mo><msup><mn>81<\/mn><mn>2<\/mn><\/msup><\/mrow><annotation encoding=\"application\/x-tex\">res*9^5=res*9*81^2<\/annotation><\/semantics><\/math>\uff09<\/li>\n<\/ol>\n\n\n\n<p>\u7531\u4e8e\u6bcf\u4e00\u6b21\u64cd\u4f5c\u90fd\u56de\u4f7f\u6307\u6570\/2\uff0c\u5047\u5982\u6307\u6570\u5927\u5c0f\u662fb\uff0c\u5219\u66b4\u529b\u8981\u5faa\u73afb\u6b21\uff0c\u800c\u901a\u8fc7\u5feb\u901f\u5e42\uff0c\u6211\u4eec\u6210\u529f\u4f18\u5316\u4e3aO\uff08logb\uff09\uff0c\u5373\u4ee52\u4e3a\u5e95\uff0cb\u7684\u5bf9\u6570\u3002\u8fd9\u4e2a\u4f18\u5316\u663e\u7136\u662f\u5de8\u5e45\u7684\uff0c\u90a3\u4e48\u4ee3\u7801\u4e0a\u600e\u4e48\u5b9e\u73b0\u5462\uff1f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ll qpow(ll a, ll b, ll mod)\n{\n    ll res = 1;         \/\/ \u521d\u59cb\u5316\u7ed3\u679c\u4e3a1\uff08\u4efb\u4f55\u6570\u76840\u6b21\u5e42\u4e3a1\uff09\n    a %= mod;             \/\/ \u907f\u514d\u540e\u7eed\u4e58\u6cd5\u6ea2\u51fa\u540c\u65f6\u9632\u6b62\u8f93\u5165\u7684a\u8fc7\u5927\n    \/\/ \u5f53\u6307\u6570b\u4e0d\u4e3a0\u65f6\u7ee7\u7eed\u8ba1\u7b97\n    while (b)\n    {\n        if (b % 2 == 1)\n        {\n            res *= a;   \/\/ \u5c06\u5f53\u524d\u5e42\u4e58\u5165\u7ed3\u679c\n            res %= mod;   \/\/ \u6bcf\u6b21\u4e58\u6cd5\u540e\u53d6\u6a21\uff0c\u4fdd\u8bc1\u7ed3\u679c\u5728\u6a21c\u8303\u56f4\u5185\n        }\n        a *= a;         \/\/ \u8ba1\u7b97\u4e0b\u4e00\u4f4d\u7684\u5e42\uff1aa^(2^k)\n        a %= mod;         \/\/ \u5e73\u65b9\u540e\u53d6\u6a21\uff0c\u9632\u6b62\u6ea2\u51fa\n        b \/= 2;\n    }\n\n    return res;         \/\/ \u8fd4\u56de\u6700\u7ec8\u7ed3\u679c\n}\n\/\/ \u4f7f\u7528\u524d\u9700\u8981\u786e\u4fdd\u5df2\u5b9a\u4e49 ll \u4e3a long long \u7684\u522b\u540d<\/code><\/pre>\n\n\n\n<p>\u770b\u5230\u8fd9\u6211\u4eec\u4e0d\u59a8\u56de\u60f3\u4e00\u4e0b\u524d\u6587\u63d0\u5230\u7684\u4f4d\u8fd0\u7b97\uff0c\u5224\u65ad\u6307\u6570\u662f\u5076\u6570\u8fd8\u662f\u5947\u6570\uff0c\u8fd8\u6709\u4e00\u79cd\u66f4\u9ad8\u6548\u7684\u65b9\u6cd5\u5c31\u662f\u4f7f\u7528\u4f4d\u8fd0\u7b97\u4e2d\u7684\u4e0e\uff08<strong>&amp;<\/strong>\uff09\u8fd0\u7b97\uff0c\u56e0\u4e3a1\u7684\u8865\u7801\u53ea\u6709\u6700\u540e\u4e00\u4f4d\u4e3a1\uff0c\u5176\u4f59\u5168\u4e3a0\u3002\u5982\u679cb\u662f\u5947\u6570\u7684\u8bdd\uff0c\u90a3\u5b83\u7684\u6700\u540e\u4e00\u4f4d\u4e3a1\uff0cb&amp;1\u7684\u7ed3\u679c\u5c31\u662f1\uff0c\u5982\u679cb\u662f\u5076\u6570\uff0c\u90a3\u6700\u540e\u4e00\u4f4d\u4e3a0\uff0cb&amp;1\u7684\u7ed3\u679c\u662f0\u3002<\/p>\n\n\n\n<p>\u540c\u65f6b\/=2\u8fd9\u91cc\uff0c\u6211\u4eec\u53ef\u4ee5\u7528<strong>b &gt;&gt;= 1<\/strong>\u4ee3\u66ff\uff08\u6574\u6570\u7b97\u672f<strong>\u53f3\u79fb\u4e00\u4f4d<\/strong>\u76f8\u5f53\u4e8e<strong>\u9664\u4ee52\u5e76\u5411\u4e0b\u53d6\u6574<\/strong>\uff09\u3002<\/p>\n\n\n\n<p>\u6545\u800c\u6211\u4eec\u5f97\u5230\u5feb\u901f\u5e42\u6700\u7ec8\u7248\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ll qpow(ll a, ll b, ll mod)\n{\n    ll res = 1;\n    a %= mod;\n    while (b)\n    {\n        if (b &amp; 1)\n            res = res * a % mod; \/\/ \u5f53\u524d\u4f4d\u4e3a1\u65f6\u7d2f\u4e58\n        a = a * a % mod;         \/\/ \u5e95\u6570\u5e73\u65b9\n        b &gt;&gt;= 1;                 \/\/ \u6307\u6570\u53f3\u79fb\n    }\n    return res;\n}<\/code><\/pre>\n\n\n\n<p>\u76f8\u5173\u4e60\u9898\u5f85\u6211\u4f18\u9009\u540e\u5217\u51fa\uff0c\u4e0b\u4e00\u7bc7\u89c1~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4f4d\u8fd0\u7b97\u6cd5\u5219 1.\u4f4d\u8fd0\u7b97\u6982\u8ff0 \u5728\u73b0\u4ee3\u8ba1\u7b97\u673a\u4e2d\uff0c\u6240\u6709\u6570\u636e\u90fd\u4ee5\u4e8c\u8fdb\u5236\u5f62\u5f0f\u5b58\u50a8\uff0c\u5373 0 \u548c 1 \u4e24\u79cd\u72b6\u6001\u3002\u8ba1\u7b97\u673a\u5bf9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":156,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,15,12],"tags":[],"class_list":["post-204","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-article","category-algorithm-template","category-programming-algorithm-road"],"_links":{"self":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":13,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":449,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/posts\/204\/revisions\/449"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/media\/156"}],"wp:attachment":[{"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/media?parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/categories?post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jiangqvweihuan.cn\/index.php\/wp-json\/wp\/v2\/tags?post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}