#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
const int mxn = 5e6+7 ;
using namespace std;
typedef long long ll;
ll p,t,n,m, si , a[mxn] , b[mxn] , c[mxn] , d[mxn] , rc[mxn] ,sum[mxn];
bool ans[mxn];
template <class T>
void rd(T &x){
x=0;T f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') f = -1 ; c = getchar();}
while(isdigit(c)) {x = (x<<1) + (x<<3) + (c^48);c = getchar();}
x*=f;
}
int main()
{
rd(n);
for(int i=1;i<=n;i++)
rd(a[i]) , rd(b[i]) , rd(c[i]) , rd(d[i]);
vector<ll> v1 , v2;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
v1.push_back(a[i]+b[j]) , v2.push_back(c[i]+d[j]);
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
int ans = 0 ;
for(int i=0;i<v1.size();i++){
int p = lower_bound(v2.begin(),v2.end(),-v1[i]) - v2.begin() ;
if(v2[p]+v1[i]==0){ /// 计算所有组合
while(v2[p]+v1[i]==0) ans++ , p++ ;
}
}
printf("%d\n",ans);
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#define pi acos(-1.0)
#define eps 1e-5
const int mxn = 5e6+7 ;
using namespace std;
typedef long long ll;
template <class T>
void rd(T &x){
x=0;T f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') f = -1 ; c = getchar();}
while(isdigit(c)) {x = (x<<1) + (x<<3) + (c^48);c = getchar();}
x*=f;
}
ll p,t,n,m,k,si ;
double a[mxn] ;
bool check(double x)
{
int ans = 0 ;
for(int i=1;i<=n;i++){
ans+= (int)(a[i]/x);
}
if(ans>=m+1) return true;
return false ;
}
int main()
{
rd(t);
while(t--){
rd(n) , rd(m) ;
for(int i=1;i<=n;i++)
rd(k) , a[i] = k*k*pi;
sort(a+1,a+1+n);
double l = 0 , r = a[n] ;
while(r-l>eps){
double mid = (l+r)/2.0;
if(check(mid)) l = mid ;
else r = mid ;
}
printf("%.4f\n",r);
}
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#define pi acos(-1.0)
#define eps 1e-5
const int mxn = 5e6+7 ;
using namespace std;
typedef long long ll;
template <class T>
void rd(T &x){
x=0;T f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') f = -1 ; c = getchar();}
while(isdigit(c)) {x = (x<<1) + (x<<3) + (c^48);c = getchar();}
x*=f;
}
int p,t,n,m,k,si,ans;
int a[mxn] , b[mxn] ,c[mxn];
int main()
{
int cas = 1 ;
while(~scanf("%d %d %d",&n,&m,&k)){
printf("Case %d:\n",cas++ );
si = 1 ;
for(int i=1;i<=n;i++) rd(a[i]);
for(int i=1;i<=m;i++) {
rd(p);
for(int j=1;j<=n;j++)
c[si++] = p+a[j];
}
for(int i=1;i<=k;i++) rd(b[i]);
sort(c+1,c+si);
rd(ans);
while(ans--){
int x , falg = 1 ; rd(x);
for(int i=1;i<=k;i++){
int y = lower_bound(c+1,c+si,x-b[i]) - c;
if( (x == b[i] + c[y] ) && y>=1 ){
puts("YES"); falg = 0 ;
break;
}
}
if(falg) puts("NO");
}
}
}
题解:p 为质数,那么P的因子只有1和p,而 p = a^3 - b^3 = (a-b)(a^2+ab+b^2) = 1(a^2+ab+b^2) = 3b^2 + 3*b + 1
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#define pi acos(-1.0)
#define eps 1e-5
const int mxn = 5e6+7 ;
using namespace std;
typedef long long ll;
template <class T>
void rd(T &x){
x=0;T f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') f = -1 ; c = getchar();}
while(isdigit(c)) {x = (x<<1) + (x<<3) + (c^48);c = getchar();}
x*=f;
}
ll p,t,n,m,k,si,ans;
int a[mxn] , b[mxn] ,c[mxn];
int main()
{
rd(t);
while(t--){
rd(n); ll l = 1 , r = 1000000+7, falg = 1 ;
while(l<=r){
ll mid = (l+r)>>1;
if(1ll*3*mid*mid + 1ll*3*mid + 1==n){
puts("YES"); falg = 0 ; break;
}
if(1ll*3*mid*mid+1ll*3*mid+1>n) r = mid-1 ;
else l = mid+1 ;
}
if(falg) puts("NO");
}
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#define pi acos(-1.0)
#define eps 1e-5
const int mxn = 1e9+7 ;
const int lim = 1e6+7 ;
using namespace std;
typedef long long ll;
template <class T>
void rd(T &x){
x=0;T f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') f = -1 ; c = getchar();}
while(isdigit(c)) {x = (x<<1) + (x<<3) + (c^48);c = getchar();}
x*=f;
}
ll p,t,n,m,k,si,ans;
ll a[lim] ;
int main()
{
for(ll i=1;i<mxn;i<<=1){
for(ll j=1;j*i<mxn;j*=3){
for(ll k=1;k*j*i<mxn;k*=5){
for(ll x=1;i*j*k*x<mxn;x*=7){
a[m++] = i*j*k*x;
}
}
}
}
sort(a,a+m);
rd(n);
while(n--){
rd(k);
printf("%lld\n",*lower_bound(a,a+m,k));
}
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#define pi acos(-1.0)
#define eps 1e-5
const int mxn = 1e9+7 ;
const int lim = 1e6+7 ;
using namespace std;
typedef long long ll;
template <class T>
void rd(T &x){
x=0;T f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') f = -1 ; c = getchar();}
while(isdigit(c)) {x = (x<<1) + (x<<3) + (c^48);c = getchar();}
x*=f;
}
ll p,t,n,m,k,si,ans;
ll a[lim] ;
int main()
{
rd(n); n<<=1;
int falg = 1;
for(int i=1;i<=sqrt(n);i++){
ll ans = n-i*(i+1) ;
ll l = 1 , r = sqrt(ans) + 1 ;
while(l<r){
ll mid = (l+r)>>1;
if(mid*(mid+1)==ans){
puts("YES");
falg = 0 ;
break;
} else if(mid*(mid+1)>ans) {
r = mid - 1 ;
} else {
l = mid + 1;
}
}
if(!falg) break;
}
if(falg) puts("NO");
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#define pi acos(-1.0)
#define eps 1e-5
const int mxn = 1e9+7 ;
const int lim = 1e6+7 ;
using namespace std;
typedef long long ll;
template <class T>
void rd(T &x){
x=0;T f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') f = -1 ; c = getchar();}
while(isdigit(c)) {x = (x<<1) + (x<<3) + (c^48);c = getchar();}
x*=f;
}
ll p,t,n,m,k,si,ans;
ll a[lim] ;
bool check(ll x)
{
ll cnt = x , p = k;
while(x/p){
cnt += x/p;
p*=k;
}
if(cnt>=n) return false ;
return true ;
}
int main()
{
rd(n) , rd(k);
ll l = 1 , r = n ;
while(l<=r){
ll mid = (r+l)>>1;
if(check(mid)) l = mid + 1 ;
else r = mid - 1 ;
}
printf("%d\n",l);
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#define pi acos(-1.0)
#define eps 1e-9
const int mxn = 1e9+7 ;
const int lim = 1e6+7 ;
using namespace std;
typedef long long ll;
template <class T>
void rd(T &x){
x=0;T f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') f = -1 ; c = getchar();}
while(isdigit(c)) {x = (x<<1) + (x<<3) + (c^48);c = getchar();}
x*=f;
}
ll p,t,n,m,k,si,ans;
ll a[lim] ;
double check(double x)
{
return 8*x*x*x*x + 7*x*x*x + 2*x*x + 3*x + 6 ;
}
int main()
{
rd(t);
while(t--){
double n , l = -100 , r = 101 , mid ;
scanf("%lf",&n);
while(r-l>eps){
mid = (l+r)/2.0;
if(check(mid)>=n)
r = mid ;
else
l = mid ;
}
if(mid<0 || mid >100){
puts("No solution!");
} else {
printf("%.4f\n",mid);
}
}
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#define pi acos(-1.0)
#define eps 1e-9
const int mxn = 1e9+7 ;
const int lim = 1e6+7 ;
using namespace std;
typedef long long ll;
template <class T>
void rd(T &x){
x=0;T f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') f = -1 ; c = getchar();}
while(isdigit(c)) {x = (x<<1) + (x<<3) + (c^48);c = getchar();}
x*=f;
}
ll p,t,n,m,k,si,ans;
ll a[lim] ;
double check(double x) {
return 42*pow(x,6.0)+48*pow(x,5.0)+21*pow(x,2.0)+10*x;
}
double res(double x,double y){
return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-x*y;
}
int main()
{
rd(t); double n;
while(t--){
scanf("%lf",&n);
double l = 0 , r = 101 , mid ;
while(r-l>eps){
mid = (l+r)/2.0;
if(check(mid)>=n)
r = mid ;
else
l = mid ;
}
printf("%.4f\n",res(mid,n));
}
}