Reminder: in case of any technical issues, you can use the lightweight website m1.codeforces.com, m2.codeforces.com, m3.codeforces.com. ×

Coder_Shubham_24's blog

By Coder_Shubham_24, history, 3 years ago, In English

I was solving this question Pythagorean Theorem II

and saw some optimized solution based on this relation seems

Saw some solved optimized codes using this relations seems gcd(a,b,c)=1

int n,m=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;(i*i+j*j<=n&&i>j);j++)
		{
			if((i-j)%2==1)
				if(gcd(i,j)==1)
					m+=n/(i*i+j*j);
		}
	}
	cout<<m;

I know a,b,c are relatively prime but is it enough to know that ?

Can somebody tell me proof of this approach ?

Full text and comments »

  • Vote: I like it
  • -16
  • Vote: I do not like it

By Coder_Shubham_24, history, 3 years ago, In English

I didn't get logic for these to lines

  1. f |= (ch == '-')
  2. x = (x << 1) + (x << 3) + (ch ^ 48);
template<class T>void read(T& x)
{
	x = 0; int f = 0; char ch = getchar();
	while (ch < '0' || ch>'9') { f |= (ch == '-'); ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
	x = f ? -x : x;
	return;
}

Full text and comments »

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