[构造 数学推导] HDU 5847 Different Sums

一道可怕的构造题
题解及推导

#include
#include
#include

const int maxn=10000;
const int N=2005;

int vst[maxn+5]={1,1,0};  
int s[N];

int main(){
  int Q,n;
  freopen("t.in","r",stdin);
  freopen("t.out","w",stdout);
  for (int i=2;i<=maxn;i++)
    if (!vst[i])  
      for (int j=i+i;j1;  
  scanf("%d",&Q);
  while (Q--){
    scanf("%d",&n);
    int p;
    for (p=n+1;vst[p];p++);    
    for (int x=1;xx++){  
      int flag=0;
      for (int i=1;i<=n && !flag;i++){  
    s[i]=2*i*p+(i*(i+1)/2*x)%p;  
    if (s[i]-s[i-1]>=3*n+18) flag=1;
      }  
      if(!flag) break;
    }
    for (int i=1;i<=n;i++)
      printf("%d ",s[i]-s[i-1]);
    printf("\n");
  }
  return 0;  
}

你可能感兴趣的:(构造)