Moderator: Board moderators
#include<stdio.h>
void main()
{
unsigned long long n,x,p;
while(scanf("%llu",&n)==1)
{
x=1;
while((p=x*(x+1)/2)<n)
{
if(p>=n)
break;
else
x++;
}
printf("%llu/%llu\n",1+(p-n),x-(p-n));
}
}
CodeMaker wrote:Hi, I got TLE, can anyone say what's wrong ?
- Code: Select all
#include<stdio.h>
void main()
{
unsigned long long n,x,p;
while(scanf("%llu",&n)==1)
{
x=1;
while((p=x*(x+1)/2)<n)
{
if(p>=n)
break;
else
x++;
}
printf("%llu/%llu\n",1+(p-n),x-(p-n));
}
}
gvcormac wrote:I suggest that it is your responsibility to explain why your program should work than to invite others to find errors.
#include<stdio.h>
void main()
{
unsigned long long n,x,p;
while(scanf("%llu",&n)==1)
{
x=1;
while((p=x*(x+1)/2)<n)
{
if(p>=n)
break;
else
x++;
}
printf("%llu/%llu\n",1+(p-n),x-(p-n));
}
}
function(int N) {
int res;
res = ceil(((-1 + sqrt(1 + 4.0 * 2.0 * N))/(double)2.0));
int ans = ((((res * res) + res) /(double) 2.0));
printf("%d/%d\n", (ans - N) + 1,res);
}

Users browsing this forum: No registered users and 0 guests