{"id":5064,"date":"2020-09-13T14:45:34","date_gmt":"2020-09-13T11:45:34","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=5064"},"modified":"2020-09-13T20:35:40","modified_gmt":"2020-09-13T17:35:40","slug":"e-olymp-4142-%d0%b1%d0%be%d0%bb%d1%8c%d1%88%d0%be%d0%b9-xor","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=5064","title":{"rendered":"e-olymp 4142. \u0411\u043e\u043b\u044c\u0448\u043e\u0439 XOR"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u0414\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u043e\u0433\u043e $x$ \u043d\u0430\u0439\u0442\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u0438\u0445 $a$, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044e:<\/p>\n<ul>\n<li>$ a $ xor $x &gt; x $<\/li>\n<li>$ 0 &lt; a &lt; x $<\/li>\n<\/ul>\n<p>\u0433\u0434\u0435 $a$ \u0438 $x$ &#8212; \u0446\u0435\u043b\u044b\u0435, xor &#8212; \u0431\u0438\u0442\u043e\u0432\u044b\u0439 XOR \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440.<\/p>\n<p>\u0418\u043c\u0435\u044e\u0442\u0441\u044f $q$ \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e $x$. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 $a$, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c \u0432\u044b\u0448\u0435.<\/p>\n<h2>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 $q$ $(1 \\leqslant q \\leqslant 10^5)$. \u041a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 $q$ \u0441\u0442\u0440\u043e\u043a \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 $x$ $(1 \\leqslant x \\leqslant 10^{10})$.<\/p>\n<h2>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 $a$, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u043c.<\/p>\n<h1>\u0422\u0435\u0441\u0442\u044b<\/h1>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\u2116<\/td>\n<td>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<td>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>2<br \/>\n2<br \/>\n10<\/td>\n<td>1<br \/>\n5<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>3<br \/>\n13<br \/>\n3<br \/>\n16<\/td>\n<td>2<br \/>\n0<br \/>\n15<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>5<br \/>\n1<br \/>\n7<br \/>\n4294967295<br \/>\n42<br \/>\n451<\/td>\n<td>0<br \/>\n0<br \/>\n0<br \/>\n21<br \/>\n60<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>\u041a\u043e\u0434<\/h1>\n<pre class=\"lang:java decode:true \">import java.util.*;\r\n\r\nclass Main{\r\n\tpublic static void main (String[] args){\r\n\t\tScanner in = new Scanner(System.in);\r\n\t\tlong q, x, res, two; \r\n\t\tq = in.nextInt();\r\n\t\tfor(long i = 0; i &lt; q; ++ i){\r\n\t\t\tx = in.nextLong();\r\n\t\t\tres = 0;\r\n\t\t\ttwo = 1; \/\/ two = 2^0\r\n\t\t\twhile(x &gt; 0){\r\n\t\t\t\tif(x % 2 == 0) \/\/ check if the last bit is equal to zero\r\n\t\t\t\t\tres += two;\r\n\t\t\t\tx &gt;&gt;= 1;\t\/\/ moving to the next bit\r\n\t\t\t\ttwo &lt;&lt;= 1; \/\/ same as two *= 2\r\n\t\t\t}\r\n\t\t\tSystem.out.println(res);\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<h1>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>XOR \u0432\u044b\u0434\u0430\u0451\u0442 \u0447\u0438\u0441\u043b\u043e, \u0431\u0438\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u0430\u0432\u043d\u044b $1$, \u043a\u043e\u0433\u0434\u0430 \u043b\u0438\u0448\u044c \u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0447\u0438\u0441\u0435\u043b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0431\u0438\u0442 \u0440\u0430\u0432\u0435\u043d $1$. \u0427\u0438\u0441\u043b\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0447\u0435\u043c $x$ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043b\u0438\u0448\u044c \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 $2^{k}\\leqslant a&lt;2^{k+1}$, \u0433\u0434\u0435 $k$- \u043d\u043e\u043c\u0435\u0440 \u0431\u0438\u0442\u0430 \u0447\u0438\u0441\u043b\u0430 $x$, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e. \u0422\u0430\u043a\u0438\u0445 $a$ \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 $2^k$ \u0448\u0442\u0443\u043a \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0438\u0442\u0430.<\/p>\n<li>\u0417\u0430\u0434\u0430\u0447\u0430 \u043d\u0430 <a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/4142\" rel=\"noopener noreferrer\" target=\"_blank\">e-olymp<\/a><\/li>\n<li>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043d\u0430 <a href=\"https:\/\/ideone.com\/BBL1Mw\" rel=\"noopener noreferrer\" target=\"_blank\">ideone<\/a><\/li>\n<li>\u0417\u0430\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0435 <a href=\"https:\/\/www.e-olymp.com\/ru\/submissions\/7316853\" rel=\"noopener noreferrer\" target=\"_blank\">\u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0414\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u043e\u0433\u043e $x$ \u043d\u0430\u0439\u0442\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0430\u043a\u0438\u0445 $a$, \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0438\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044e: $ a $ xor $x &gt; x $ $ 0 &lt; a &lt; x $ \u0433\u0434\u0435 $a$ \u0438 $x$ &#8212; \u0446\u0435\u043b\u044b\u0435, xor &#8212; \u0431\u0438\u0442\u043e\u0432\u044b\u0439 XOR \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440. \u0418\u043c\u0435\u044e\u0442\u0441\u044f $q$ \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e $x$. \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 $a$, &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=5064\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":166,"featured_media":5069,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[699,698,141,231,102],"jetpack_featured_media_url":"https:\/\/java.mazurok.com\/wp-content\/uploads\/xor-gate-symbol1.jpg","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/5064"}],"collection":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/users\/166"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5064"}],"version-history":[{"count":3,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/5064\/revisions"}],"predecessor-version":[{"id":5067,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/5064\/revisions\/5067"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/media\/5069"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}