Pagini recente » Cod sursa (job #1355607) | Cod sursa (job #2430684) | Cod sursa (job #2342779) | Cod sursa (job #2914195) | Cod sursa (job #16790)
Cod sursa(job #16790)
#include <stdio.h>
long n,k;
int main()
{
long i,m,p;
freopen("farfurii.in","r",stdin);
freopen("farfurii.out","w",stdout);
scanf("%ld%ld",&n,&k);
for(p=1;p<n;p=p<<1);
for(m=0;p>0;p=p>>1)
if(m+p<=n && (m+p)*(m+p-1)<=2*k) m+=p;
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);
putchar('\n');
}
else
{
k=m-k; m++;
for(i=1;i<=n-m;i++) printf("%ld ",i);
printf("%ld ",n-k);
for(i=n;i>n-k;i--) printf("%ld ",i);
for(i=n-k-1;i>n-m;i--) printf("%ld ",i);
putchar('\n');
}
return 0;
}