# 【BZOJ 4589】Hard Nim

### 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];

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;
}


## 58 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!!

4. g说道：

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!

5. g说道：

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

6. This post will help the internet viewers for creating new web site or even a blog from start to end.

7. 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.

8. Wonderful, what a web site it is! This weblog gives useful data to us, keep it up.

9. I every time used to read paragraph in news papers but now as I am a user of internet so from now I
am using net for posts, thanks to web.

10. 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!

11. 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.

12. I always spent my half an hour to read this weblog’s articles or reviews everyday along
with a mug of coffee.

13. 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!

14. 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!

15. Greetings! Very helpful advice in this particular article! It is the little changes that make the biggest changes.

Thanks a lot for sharing!

16. No matter if some one searches for his necessary thing, so he/she
desires to be available that in detail, thus that thing is maintained over here.

17. 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!

18. I don’t even know how I ended up right here, but I thought this post was good.
I do not realize who you’re however certainly you are going to a well-known blogger in case you are

19. 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!

20. 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.

21. 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!

22. What’s up to every single one, it’s genuinely a nice for me to
go to see this web page, it consists of priceless Information.

23. 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!

24. What’s up to all, because I am in fact eager of reading this website’s post
to be updated daily. It carries pleasant material.

25. Pretty nice post. I just stumbled upon your weblog and wanted to say that I’ve
really enjoyed surfing around your blog posts.
In any case I’ll be subscribing to your rss feed and I hope you write again very soon!

26. 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

27. I really like what you guys are up too. This kind of clever work and coverage!
Keep up the awesome works guys I’ve incorporated you guys to my
blogroll.

28. 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.

29. 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.

30. Hi, nice work. I really appeaciate the information you are providing through your website, i have alwasy find it helpful. Keep up the awsome work.

31. 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.

32. I’m not that much of a internet reader to be honest but your sites really
to come back later. All the best

33. 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

34. Heya i’m for the first time here. I came
across this board and I to find It really helpful & it helped me out much.
I hope to provide something back and help others like you aided me.

35. 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
OK? Not that I’m complaining, but sluggish loading instances times will very frequently affect your
could look out for much more of your respective intriguing content.
Ensure that you update this again very soon.

36. 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.

37. 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!

38. I relish, cause I found just what I was looking for.
You have ended my four day lengthy hunt! God Bless you man. Have a nice day.
Bye

39. 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.

40. 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

41. 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 😉

42. Every weekend i used to pay a visit this site,
for the reason that i wish for enjoyment, as this this web page conations truly pleasant funny material too.

43. 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.

44. 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.

45. Hi there to every body, it’s my first go to see of this blog; this website consists
of amazing and genuinely fine information in favor

46. This info is worth everyone’s attention. When can I find out more?

47. 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.

48. 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!

49. Wonderful article! We are linking to this great content on our website.

Keep up the good writing.

50. 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!

51. I am genuinely thankful to the owner of this web site who has shared this impressive article at here.

52. 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.

53. Hey there! Do you use Twitter? I’d like to follow you if
that would be ok. I’m undoubtedly enjoying your blog and look forward to new posts.

54. Amazing things here. I am very satisfied to see your post.
Thanks a lot and I’m having a look ahead to contact you.

Will you please drop me a e-mail?

55. Good day! Do you use Twitter? I’d like to follow you if that would
be okay. I’m definitely enjoying your blog and look forward to new posts.

56. 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.