{"id":855,"date":"2020-10-11T23:41:55","date_gmt":"2020-10-11T15:41:55","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=855"},"modified":"2020-11-04T17:54:46","modified_gmt":"2020-11-04T09:54:46","slug":"lagrange%e6%8f%92%e5%80%bc%e7%bb%83%e4%b9%a0%e9%a2%98","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/10\/11\/lagrange%e6%8f%92%e5%80%bc%e7%bb%83%e4%b9%a0%e9%a2%98\/","title":{"rendered":"Lagrange\u63d2\u503c\u7ec3\u4e60\u9898"},"content":{"rendered":"<p>[toc]<\/p>\n<h4><a href=\"https:\/\/vjudge.net\/problem\/%E8%AE%A1%E8%92%9C%E5%AE%A2-42588\">XOR Sum<\/a><\/h4>\n<p>\u8bbe<code class=\"katex-inline\">f(i, k) = 1 \\bigoplus 2 \\bigoplus 3 ...\\bigoplus i^k<\/code><br \/>\n\u7ed9\u5b9a\u4e09\u4e2a\u6574\u6570t, x, y, \u6c42\u4e0b\u9762\u516c\u5f0f\u5bf91e9+7\u53d6\u6a21\u7684\u503c\u3002<\/p>\n<p><code class=\"katex-inline\">\\sum_{k=1}^{t} \\sum_{i=x}^{y} f(i, k)<\/code><\/p>\n<p>\u62c9\u683c\u6717\u65e5\u63d2\u503c\u6c42\u89e3\u3002\u3002<br \/>\n\u9996\u5148\u5206\u6790f\u51fd\u6570\uff0c\u53d1\u73b0\uff1a<br \/>\n<img src=\"http:\/\/www.zyhcoding.club:80\/wp-content\/uploads\/2020\/10\/\u516c\u5f0f.png\" alt=\"\" \/><br \/>\n\u53ef\u4ee5\u636e\u6b64\u6765\u63a8\u516c\u5f0f<br \/>\n<code class=\"katex-inline\">\\sum_{k=1}^{t} \\sum_{i=x}^{y} f(i, k) = \\sum_{k=1}^{t} \\sum_{i=1}^{y} f(i, k) - \\sum_{k=1}^{t} \\sum_{i=1}^{x-1} f(i, k)<\/code><br \/>\n<code class=\"katex-inline\">\\sum_{k=1}^{t} \\sum_{i=1}^{x} f(i, k) = \\sum_{k=1}^{t} \\sum_{i=1}^{x} i^k[i^k\\%2==0] + \\sum_{k=1}^{t} \\sum_{i=1}^{x} [i^k\\%4 == 1 or 2]<\/code><br \/>\n\u5bf9\u4e8e\u4e0a\u5f0f<\/p>\n<pre><code class=\"language-c++\">#include &lt;bits\/stdc++.h&gt;\n\nusing namespace std;\ntypedef long long ll;\nconst ll maxn = 1e5+5, mod = 1e9+7;\nll t, a, b;\nll pre[maxn], suf[maxn], fac[maxn], y[maxn];\nll pow_mod(ll a, ll b){\n    a %= mod, b %= mod-1;\n    if (!a) return 0;\n    ll ans = 1;\n    while (b){\n        if (b&amp;1)    ans = ans*a%mod;\n        b &gt;&gt;= 1;\n        a = a*a%mod;\n    }\n    return ans;\n}\nll inv(ll a){\n    a = (a%mod+mod)%mod;\n    return pow_mod(a, mod-2);\n}\nll Lagrange(ll x){\n    ll ans = t*(x\/4%mod+((x%4)?1:0)) + x\/4%mod + (x%4&gt;=2) + t\/2*(x\/4%mod+(x%4&gt;=3));\n    pre[0] = suf[t+2+1] = 1;\n    x \/= 2;     x %= mod;\n    for (int i=1; i&lt;=t+2; i++)  pre[i] = pre[i-1]*(x-i)%mod;\n    for (int i=t+2; i&gt;=1; i--)  suf[i] = suf[i+1]*(x-i)%mod;\n    for (int i=1; i&lt;=t+2; i++){\n        int flag = 1;\n        if ((t+2-i)&amp;1)  flag = -1;\n        ans = (ans + y[i]*pre[i-1]%mod*suf[i+1]%mod*inv(fac[i-1])%mod*inv(fac[t+2-i])%mod*flag)%mod;\n    }\n    return ans;\n}\n\nint main(){\n    ll ans;\n    cin &gt;&gt; t &gt;&gt; a &gt;&gt; b;\n    fac[0] = 1;\n    for (int i=1; i&lt;=t+3; i++)  fac[i] = fac[i-1]*i%mod;\n    for (ll i=1; i&lt;=t+2; i++)  y[i] = (y[i-1]+2*i*(pow_mod(2*i, t)-1)%mod*inv(2*i-1)%mod)%mod;\n    ans = Lagrange(b) - Lagrange(a-1);\n    ans = (ans%mod+mod)%mod;\n    cout &lt;&lt; ans;\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>[toc] XOR Sum \u8bbef(i, k) = 1 \\bigoplus 2 \\bigoplus 3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[60],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/855"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=855"}],"version-history":[{"count":14,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/855\/revisions"}],"predecessor-version":[{"id":860,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/855\/revisions\/860"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=855"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}