题目:http://acm.nyist.net/JudgeOnline/problem.php?pid=85
#include <stdio.h>
int main()
{
int n,s;
scanf("%d",&n);
while(n--)
{
scanf("%d",&s);
int i = 1;
while(i)
{
s = s - i;
if(s <= 0)
break;
++i;
}
int k = s + i;
if(i%2==0)
printf("%d/%d\n",k,i-k+1);
else
printf("%d/%d\n",i-k+1,k);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int count=scanner.nextInt();
for(int i=0;i<count;i++)
{
int loc=scanner.nextInt();
int j=1;
while(j>0)
{
loc=loc-j;
if(loc<=0)
{
break;
}
++j;
}
int k=loc+j;
if(j%2==0)
{
int x=k;
int y=j-k+1;
System.out.println(x+"/"+y);
}else{
int y=k;
int x=j-k+1;
System.out.println(x+"/"+y);
}
}
scanner.close();
}
}
#include <stdio.h>
#include <math.h>
void main()
{
int n,m,x,y;
scanf("%d\n",&m);
while(m--)
{
scanf("%d",&n);
x=(int)(sqrt((float)2*n)-0.5);//“sqrt”: 对重载函数的调用不明确
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);
}
}