Cod sursa(job #29248)
Utilizator | Data | 8 martie 2007 20:19:37 | |
---|---|---|---|
Problema | Farfurii | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.51 kb |
#include<stdio.h>
#include<math.h>
long n,k,m,i,j,p;
int main()
{freopen("farfurii.in","r",stdin);
freopen("farfurii.out","w",stdout);
scanf("%ld %ld",&n,&k);
for(p=1;p<n;p=p*2);
for(m=0;m<n&&m*(m+1)<=2*k;m++);
k=k-m*(m-1)/2;
if(!k){
for(i=1;i<=n-m;i++)
printf("%ld ",i);
for(i=n;i>n-m;i--)
printf("%ld ",i);}
else {k=m-k;m++;
for(i=1;i<=n-m;i++)
printf("%ld ",i);
printf("%ld ",n-k);
for(i=n;i>n-m;i--)
if(i!=n-k) printf("%ld ",i);}
putchar ('\n');
fclose(stdout);
return 0;}