NYOJ85 有趣的数

原题链接


 
#include <stdio.h>
#include <math.h>

int main(){
	int m, n, x, y, t;
	scanf("%d", &m);
	while(m--){
		scanf("%d", &n);
		x = 0; y = 1;
		for(int i = 1; (t = (1 + i) * i / 2) < n; ++i)
			x = i, y = n - t;
		x += 2;
		if(x & 1) printf("%d/%d\n", y, x - y);
		else printf("%d/%d\n", x - y, y);		
	}
	return 0;
}        

标程

 
#include <stdio.h>
#include <math.h>
main()
{
	int n,m,x,y;
	scanf("%d\n",&m);
	while(m--)
	{
		scanf("%d",&n);
		x=(int)(sqrt(2*n)-0.5);
		y=n-x*(x+1)/2;
		if(x%2==0)
			printf("%d/%d\n",x+2-y,y);

		else
			printf("%d/%d\n",y,x+2-y);
	}
}
        


posted on 2014-03-18 21:45  长木Qiu  阅读(149)  评论(0编辑  收藏  举报