【BZOJ 2296】[POJ Challenge] 随机种子

相关链接

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

解题报告

我们假设高位是$9876543201$,低$6$位随意
那么每一次加上$x$,导致高位至多增加$1$
所以一定有解,至于是多少倍?我们可以二分

Code

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

const LL MX = 9876543201999999;
const LL MN = 9876543201000000; 

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

int main() {
	for (int T = read(); T; T--) {
		LL x = read();
		if (!x) {
			puts("-1");
		} else {
			LL r = MX / x + 1, l = MN / x;
			while (l <= r) {
				LL mid = l + r >> 1;
				if (x * mid < MN) {
					l = mid + 1;
				} else if (x * mid > MX) {
					r = mid - 1;
				} else {
					printf("%lld\n", mid * x);
					break;
				}
			}
		}
	}
	return 0;
}

25 thoughts to “【BZOJ 2296】[POJ Challenge] 随机种子”

  1. Thank you for another excellent article. The place else may anyone
    get that kind of info in such a perfect means of writing?
    I have a presentation subsequent week, and I am at the search for such info.

  2. You’re so interesting! I don’t believe I have read a single thing like this
    before. So great to discover someone with original thoughts
    on this topic. Really.. thanks for starting this up. This web site is something that’s needed on the internet, someone with a little originality!

  3. Hi! This is kind of off topic but I need some guidance from an established blog.
    Is it very difficult to set up your own blog?
    I’m not very techincal but I can figure things
    out pretty quick. I’m thinking about making my own but I’m not
    sure where to begin. Do you have any ideas or suggestions?

    Appreciate it

  4. I like the helpful info you provide in your articles.
    I’ll bookmark your weblog and check again here frequently.

    I am quite certain I will learn many new stuff right here!
    Good luck for the next!

  5. Great goods from you, man. I’ve have in mind your stuff
    previous to and you’re just too fantastic. I actually like
    what you have obtained right here, certainly like what
    you are saying and the best way by which you say it.
    You make it entertaining and you continue to take care of to stay it sensible.
    I cant wait to learn far more from you. That is actually a wonderful site.

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

  7. Hi there, i read your blog occasionally and i own a similar
    one and i was just curious if you get a lot of spam remarks?
    If so how do you protect against it, any plugin or anything you can advise?

    I get so much lately it’s driving me insane so any help is very much appreciated.

  8. That is a very good tip particularly to those fresh to the blogosphere.
    Brief but very precise information… Thank you for sharing this one.
    A must read article!

  9. I like the helpful info you provide in your articles.

    I will bookmark your blog and check again here regularly. I’m
    quite certain I will learn many new stuff right here!
    Good luck for the next!

  10. Hey this is kind of of off topic but I was
    wanting to know if blogs use WYSIWYG editors or if you
    have to manually code with HTML. I’m starting a blog soon but have no coding know-how so I wanted to get guidance from someone with experience.
    Any help would be enormously appreciated!

  11. Hello! I’ve been following your web site for a while now and finally
    got the bravery to go ahead and give you a shout out from New
    Caney Texas! Just wanted to mention keep up the excellent work!

  12. Hi just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading properly.
    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 outcome.

Leave a Reply

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