【BZOJ 4589】Hard Nim

相关链接

题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4589

解题报告

我们考虑用SG函数来暴力DP
显然可以用FWT来优化多项式快速幂
总的时间复杂度:$O(n \log n)$

Code

#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int N = 100009; 
const int MOD = 1000000007;
const int REV = 500000004;

bool vis[N];
int arr[N];

inline int read() {
	char c = getchar(); int ret = 0, f = 1;
	for (; c < '0' || c > '9'; f = c == '-'? -1: 1, c = getchar());
	for (; '0' <= c && c <= '9'; ret = ret * 10 + c - '0', c = getchar());
	return ret * f;
}

inline int Pow(int w, int t) {
	int ret = 1;
	for (; t; t >>= 1, w = (LL)w * w % MOD) {
		if (t & 1) {
			ret = (LL)ret * w % MOD;
		}
	}
	return ret;
}

inline void FWT(int *a, int len, int opt = 1) {
	for (int d = 1; d < len; d <<= 1) {
		for (int i = 0; i < len; i += d << 1) {
			for (int j = 0; j < d; j++) {
				int t1 = a[i + j], t2 = a[i + j + d];
				if (opt == 1) {
					a[i + j] = (t1 + t2) % MOD;
					a[i + j + d] = (t1 - t2) % MOD;
				} else {
					a[i + j] = (LL)(t1 + t2) * REV % MOD;
					a[i + j + d] = (LL)(t1 - t2) * REV % MOD;
				}
			}
		}
	}
}

int main() {
	for (int n, m; ~scanf("%d %d", &n, &m); ) {
		memset(arr, 0, sizeof(arr));
		for (int i = 2; i <= m; i++) {
			if (!vis[i]) {
				arr[i] = 1;
				for (int j = i << 1; 0 <= j && j <= m; j += i) {
					vis[j] = 1;
				}
			}
		}
		int len = 1; 
		for (; len <= m; len <<= 1);
		FWT(arr, len);
		for (int i = 0; i < len; i++) {
			arr[i] = Pow(arr[i], n);
		}
		FWT(arr, len, -1);
		printf("%d\n", (arr[0] + MOD) % MOD);
	}
	return 0;
}

96 thoughts to “【BZOJ 4589】Hard Nim”

  1. You actually make it seem so easy with your presentation but
    I find this matter to be actually something which I
    think I would never understand. It seems too complicated and extremely broad for me.
    I am looking forward for your next post, I’ll try to
    get the hang of it!

  2. Oh my goodness! Incredible article dude!
    Thank you so much, However I am encountering issues with your RSS.
    I don’t know the reason why I cannot subscribe to
    it. Is there anybody getting similar RSS issues? Anyone who knows the solution will you kindly respond?
    Thanx!!

  3. Hey! Do you know if they make any plugins to assist with Search
    Engine Optimization? I’m trying to get my blog to rank
    for some targeted keywords but I’m not seeing very good success.
    If you know of any please share. Thank you!

  4. Hi there to every one, as I am actually eager of reading this webpage’s post to be updated regularly.
    It carries fastidious material.

  5. I do agree with all the ideas you have introduced for your post.
    They are really convincing and will definitely work.
    Still, the posts are too brief for starters. May you please extend them a bit from next time?

    Thanks for the post.

  6. Wow that was strange. I just wrote an really long comment
    but after I clicked submit my comment didn’t show up.
    Grrrr… well I’m not writing all that over again.
    Anyways, just wanted to say fantastic blog!

  7. Admiring the dedication you put into your website and in depth information you provide.

    It’s great to come across a blog every once in a while that isn’t the same old rehashed material.
    Great read! I’ve bookmarked your site and I’m including your RSS
    feeds to my Google account.

  8. Hi there, just became alert to your blog through Google, and found that it is really informative.
    I am gonna watch out for brussels. I will be
    grateful if you continue this in future. Numerous people
    will be benefited from your writing. Cheers!

  9. You are so awesome! I don’t believe I have read through a single thing like
    that before. So good to find another person with a
    few genuine thoughts on this subject. Seriously..

    many thanks for starting this up. This web site is something that is
    needed on the web, someone with some originality!

  10. Hey there! I know this is sort of off-topic however I had
    to ask. Does building a well-established blog such as yours require a lot of work?
    I am brand new to writing a blog however I do write
    in my journal everyday. I’d like to start a blog so I can share
    my personal experience and feelings online. Please let me know if you have any kind of suggestions or tips for new aspiring blog
    owners. Thankyou!

  11. Hey there! I could have sworn I’ve been to this website before but
    after checking through some of the post I realized it’s new to me.
    Anyhow, I’m definitely delighted I found it and I’ll be bookmarking and checking back often!

  12. I got this website from my buddy who informed me on the topic of this web page and now this time I am
    browsing this web site and reading very informative
    articles at this place.

  13. Hello! I could have sworn I’ve been to this website
    before but after going through many of the posts I realized it’s new to
    me. Anyways, I’m certainly pleased I found it and I’ll be
    bookmarking it and checking back frequently!

  14. What i don’t understood is in truth how you’re now not really
    a lot more smartly-favored than you may be now. You are so intelligent.
    You already know therefore significantly when it comes to
    this topic, made me for my part consider it from a lot of varied angles.
    Its like women and men aren’t fascinated unless it’s one thing to do with Girl gaga!
    Your individual stuffs outstanding. At all times handle it
    up!

  15. Nice weblog right here! Additionally your web site so much up very fast!
    What web host are you the use of? Can I get your affiliate link for your host?
    I wish my website loaded up as quickly as yours lol

  16. Hmm it appears like your site ate my first comment (it was super long)
    so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog.

    I too am an aspiring blog blogger but I’m still new to everything.

    Do you have any helpful hints for newbie blog writers?
    I’d genuinely appreciate it.

  17. Pretty component of content. I simply stumbled upon your site and in accession capital to say that I get actually enjoyed account your blog posts.
    Any way I’ll be subscribing to your augment or even I achievement you get admission to constantly fast.

  18. Hello, i read your blog from time to time and i own a similar one and i was just wondering if you get a lot of spam feedback?
    If so how do you reduce it, any plugin or anything you can advise?

    I get so much lately it’s driving me mad so any support is very much appreciated.

  19. Hi there! I know this is kind of off topic but I was
    wondering if you knew where I could find a captcha plugin for my
    comment form? I’m using the same blog platform as yours and I’m
    having trouble finding one? Thanks a lot! pof natalielise

  20. hello there and thank you for your information – I have
    definitely picked up anything new from right here. I did however expertise several technical issues using this web site, since I experienced to
    reload the web site a lot of times previous to I could get it to load
    correctly. I had been wondering if your web host is
    OK? Not that I’m complaining, but sluggish loading instances times will very frequently affect your
    placement in google and can damage your quality score if ads and marketing
    with Adwords. Anyway I am adding this RSS to my e-mail and
    could look out for much more of your respective intriguing content.
    Ensure that you update this again very soon.

  21. Simply wish to say your article is as amazing. The clarity in your post is just cool and i can assume you are an expert on this subject.
    Fine with your permission allow me to grab your feed to keep up to date with forthcoming
    post. Thanks a million and please continue the gratifying work.

  22. I like the valuable information you supply to your articles.
    I will bookmark your blog and test again here regularly.
    I am reasonably certain I’ll be informed a lot of new stuff proper right here!
    Best of luck for the following!

  23. Your style is unique in comparison to other folks
    I’ve read stuff from. I appreciate you for posting when you’ve got
    the opportunity, Guess I will just bookmark this site.

  24. Great beat ! I would like to apprentice while you amend
    your website, how could i subscribe for a blog web site?

    The account helped me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright
    clear idea

  25. I have to thank you for the efforts you have put in penning this website. I’m hoping to view the same high-grade content by you later on as well. In fact, your creative writing abilities has encouraged me to get my own blog now 😉

  26. Hi there just wanted to give you a quick heads up and let you know a few of the images aren’t loading correctly.
    I’m not sure why but I think its a linking issue. I’ve tried
    it in two different internet browsers and both show the
    same outcome.

  27. Hey I am so grateful I found your weblog, I really found
    you by error, while I was browsing on Bing for something
    else, Anyways I am here now and would just like to say
    thank you for a fantastic post and a all round interesting blog (I also love the theme/design), I don’t have time to read it all at the minute but
    I have book-marked it and also included your RSS feeds, so when I have time I will be back to read a great deal more, Please
    do keep up the fantastic work.

  28. Link exchange is nothing else however it is just placing the other person’s weblog link on your page at appropriate place and other person will also do similar in favor of you.

  29. This is very interesting, You’re a very skilled blogger.
    I have joined your feed and look forward to seeking more of your excellent post.
    Also, I’ve shared your site in my social networks!

  30. Wow that was unusual. I just wrote an extremely long comment but after I clicked submit my comment didn’t
    show up. Grrrr… well I’m not writing all that over again. Regardless, just wanted to say superb blog!

  31. Fantastic beat ! I wish to apprentice while you amend your website, how can i
    subscribe for a blog site? The account helped me a acceptable deal.
    I had been a little bit acquainted of this your broadcast provided bright clear idea

  32. I was more than happy to uncover this great site.
    I wanted to thank you for your time due to this fantastic
    read!! I definitely really liked every part of it and
    i also have you bookmarked to check out new information in your web site.

  33. I was curious if you ever considered changing the structure of your blog?
    Its very well written; I love what youve got to
    say. But maybe you could a little more in the way of content
    so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 images.
    Maybe you could space it out better?

  34. The very heart of your writing whilst appearing agreeable in the beginning, did not really work well with me after some time. Somewhere throughout the paragraphs you actually managed to make me a believer unfortunately just for a while. I however have got a problem with your jumps in assumptions and you might do nicely to help fill in all those gaps. In the event that you actually can accomplish that, I will undoubtedly be amazed.

  35. Good day very cool blog!! Guy .. Excellent ..
    Superb .. I will bookmark your website and take the feeds additionally?
    I am glad to find numerous helpful info right here within the put up,
    we need develop extra techniques on this regard, thank you for sharing.

    . . . . .

  36. What i don’t understood is in truth how you are now not really much more
    smartly-liked than you may be right now. You’re so intelligent.

    You realize thus considerably in relation to this topic, made me in my view imagine
    it from so many numerous angles. Its like women and men are
    not involved except it’s one thing to do with Girl gaga! Your individual
    stuffs nice. All the time maintain it up!

  37. Hi there just wanted to give you a quick heads up
    and let you know a few of the pictures aren’t loading correctly.

    I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers
    and both show the same results.

  38. Excellent weblog here! Also your web site lots up fast! What web host
    are you using? Can I am getting your associate link to your host?
    I desire my website loaded up as quickly as yours lol

  39. Hi, i feel that i saw you visited my site thus i got here to
    go back the desire?.I am trying to to find
    issues to improve my site!I suppose its adequate to
    use a few of your concepts!!

  40. Hello There. I found your weblog using msn. That is a really well written article.

    I will make sure to bookmark it and return to read extra
    of your helpful info. Thanks for the post. I’ll certainly return.

  41. We’re a group of volunteers and starting a new scheme in our community.
    Your website offered us with valuable information to
    work on. You’ve done a formidable job and
    our entire community will be grateful to you.

  42. I was extremely pleased to discover this website. I want
    to to thank you for your time for this particularly
    wonderful read!! I definitely loved every little bit
    of it and i also have you book-marked to look at new information on your site.

  43. I blog often and I truly thank you for your content.
    Your article has truly peaked my interest. I am going to book mark your blog and keep checking
    for new information about once per week. I opted in for your RSS feed as
    well.

  44. I think this is one of the so much vital info for me.
    And i’m glad reading your article. However wanna observation on some common issues, The website style is perfect, the articles is actually
    nice : D. Just right task, cheers

  45. You actually make it seem so easy along with your presentation but I in finding this matter to be really one thing which I feel I’d never understand. It sort of feels too complicated and extremely vast for me. I am taking a look forward in your next put up, I will attempt to get the hold of it!

  46. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that
    automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you
    would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

  47. Hello there, I found your blog by the use of Google at the same time as searching
    for a comparable subject, your site came up, it appears great.
    I’ve bookmarked it in my google bookmarks.
    Hi there, simply changed into aware of your blog
    thru Google, and located that it’s really informative.
    I’m gonna be careful for brussels. I will appreciate if you proceed this in future.
    A lot of other folks might be benefited out of your
    writing. Cheers!

  48. I must thank you for the efforts you have put in penning this
    website. I am hoping to view the same high-grade content from you
    later on as well. In fact, your creative writing abilities has
    inspired me to get my very own site now 😉

  49. I’ve been absent for some time, but now I remember why I used to love this blog. Thank you, I will try and check back more frequently. How frequently you update your site?

  50. I needed to thank you for this wonderful read!!
    I absolutely loved every little bit of it. I have you saved
    as a favorite to check out new stuff you post…

Leave a Reply

Your email address will not be published. Required fields are marked *