Brackets12's blog

By Brackets12, history, 11 hours ago, In English

So today I was trying this question: 1971F - Circle Perimeter

I saw that I did not pass test 6, so I tried fixing it. Then I figured I can get some help by looking at the test case.

The test case turns out to be simple: 1 100000

So I tested the case on my computer. To my surprise it worked out. The answer was correct!! But the judging server got wrong answer! Now I was raging because I can't get it to pass on the judge so I wrote the same thing in C++. And again surprised me because it actually passed. Now these two are literally the same thing written in two different languages, but why does one work and the other one not? C++: 308206113 PASCAL: 308204979

I did some extra tests. Apparently the sums on my computer and on the judging server don't match. I made a sum that adds up all (mid * mid + x * x). My computer gave me this: 285138544 (which is correct because I verified it with the C++ program that passed), the judge gave me this: -1325314186. (negative probably because of overflow, but if they are the same sum, even the overflowed answer should be the same..) There were no overflows in the process. I tested it by this submission: 308205548 You can see in this submission that the sum was negative: 308205808

So I was wondering how you can have two different results there. It's really weird because addition cannot have two answers...

Is there a problem with the flags the judging servers for pascal is using? Or is it a problem with the PASCAL language? (I don't think it's my problem because my local code's sum matched up with the submission that passed..)

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Brackets12, history, 6 weeks ago, In English

I have seen some similar functions in problems where numbers are large and we need to mod a number like 998244353 or 1000000007 (I also noticed they are all prime). I think this function might be modular inverse??? But I don't know why any of this works and how do I use it. I don't get why I need to decrease 2 from the mod number to make it work. I don't get what the dividing by two is about. Will very appreciate if someone can help. Thank you. +++

1999F - Expected Median

const int N = 2e5 + 5, mod = 1e9 + 7;
int64_t fact[N];
int64_t pw(int64_t a, int64_t b) {
	int64_t r = 1;
	while(b > 0) {
		if(b & 1) r = (r * a) % mod;
		b /= 2;
		a = (a * a) % mod; 
	}
	return r;
}

2053D - Refined Product Optimality

int qpow(int a, int x = MOD — 2) {
	int res = 1;
	for (; x; x >>= 1, a = 1ll * a * a % MOD) if (x & 1) res = 1ll * res * a % MOD;
	return res;
}

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it