Luo Gu P5174 dot

Face questions

 

    Feeling insulted the intelligence of this water problem NM provincial election NOI-. . . .

    Direct enumeration of one-dimensional, it does not increase monotonically another dimension, and then directly calculate the answer on it. . . .

and

 

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int ha=1e9+7;

inline int add(int x,int y){ x+=y; return x>=ha?x-ha:x;}
inline void ADD(int &x,int y){ x+=y; if(x>=ha) x-=ha;}

int tqz(int x){
	ll a=x*(ll)(x+1)>>1;
	if(a%3==0) return a/3%ha*(ll)(2*x+1)%ha;
	else return a%ha*(ll)((2*x+1)/3)%ha;
}

ll R;
int ans,l,r;

int main(){
	scanf("%lld",&R);
	for(l=1,r=(int)floor(sqrt(R-1+0.001));l*(ll)l<R;l++){
		while(l*(ll)l+r*(ll)r>R) r--;
		ADD(ans,add(tqz(r),l*(ll)l%ha*(ll)r%ha));
	}
	ans=ans*4ll%ha;
	
	r=(int)floor(sqrt(R+0.001));
	ADD(ans,4*(ll)tqz(r)%ha);
	
	printf("% D \ n ", year);
	return 0;
}

  

Guess you like

Origin www.cnblogs.com/JYYHH/p/11290035.html