var i,n,a,b,s:integer;
begin
readln(n);
a:=1;
b:=1;
s:=2;
for i:=2 to n do
begin
if (a=s-1)and odd(s) or (a=1)and(s mod 2=0) then
begin
inc(s);
if odd(s) then
begin
a:=1;
b:=s-1;
end
else
begin
a:=s-1;
b:=1;
end;
continue;
end;
if odd(s) then
begin
inc(a);
dec(b);
end
else
begin
dec(a);
inc(b);
end;
end;
writeln(a,’/’,b);
end.
var i,z,b,c,n,m,a:longint;
begin
read(n);
m:=0;i:=0;
while m<n do
begin
i:=i+1;
m:=m+i;
end;
m:=m-i;
if i mod 2=0 then begin a:=1;b:=i;c:=1;end else begin a:=i;b:=1;c:=-1;end;
for i:=m to n-2 do begin a:=a+c;b:=b-c;end;
write(a,’/’,b);
end.
#include<fstream>
#include<iostream>
using namespace std;
#define fin cin
#define fout cout
//ifstream fin ("cantor.in");
//ofstream fout ("cantor.out");
long n,fraction_son,fraction_mum;
void input(){
fin>>n;
}
void fractions(){
fraction_son=fraction_mum=1;
long k=1,sum=2,module=1;
int fraction_son_add=-1,fraction_mum_add=1;
while (k<n){
if (module==sum-1){
fraction_son_add=-fraction_son_add;
fraction_mum_add=-fraction_mum_add;
sum++;k++;module=1;
if (fraction_son_add==1){
fraction_son=1;
fraction_mum=sum-1;
}
else{
fraction_son=sum-1;
fraction_mum=1;
}
}
else{
k++;module++;
fraction_son+=fraction_son_add;
fraction_mum+=fraction_mum_add;
}
}
}
void output(){
fout<<fraction_son<<’/’<<fraction_mum<<endl;
}
int main (void){
input();
fractions();
output();
return 0;
}
var n,s,i:longint;
begin
read(n);
for i:=1 to n do begin
s:=s+i;
if s>=n then break;end;
if odd(i)=true then
write(s-n+1,’/’,i+1-(s-n+1))
else write(i+1-(s-n+1),’/’,s-n+1);
end.
begin
read(n);
for i:=1 to n do
if i*(i+1)/2>=n then begin
s:=i-1; break; end;
writeln(n-s*(s+1) div 2,'/',s+2-n+s*(s+1) div 2);
end.
n,s,o:longint;
begin
readln(n);
o:=1;
s:=n;
while s-o>0 do
begin
s:=s-o;
o:=o+1;
end;
writeln((o-s+1),'/',s);
end.
const
fx1:array[1..4]of integer=(1,-1,0,1);
fy:array[1..4]of integer=(0,1,1,-1);
var
n,i,x,y,f,wfwegfg:integer;
begin
readln(n);
x:=1;
y:=1;
f:=1;
i:=1;
while i<n do
begin
x:=x+fx1[f];
y:=y+fy[f];
inc(i);
if f=1 then f:=2 else
if (f=2) and (x=1) then
f:=3 else
if f=3 then f:=4 else
if (f=4) and (y=1) then f:=1;
end;
writeln(y,'/',x);
readln;
end.
n,s,o:longint;
begin
readln(n);
o:=1;
s:=n;
while s-o>0 do
begin
s:=s-o;
o:=o+1;
end;
writeln((o-s+1),'/',s);
end.
一个错的程序 A了......
#include<cstdio>
#include<cstdlib>
#include<cmath>
int main()
{
int n;
if(n == 2) printf("1/2");
else if(n == 3) printf("2/1");
while(scanf("%d",&n)==1)
{
int k = (int)floor((sqrt(8.0*n+1)-1)/2-1e-9)+1;
int s = k*(k+1)/2;
printf("%d/%d\n",s-n+1,k-s+n);
}
system("pause");
}
利用的是代数
#include <cstring>
int n,m;
int main()
{
scanf("%d",&n);
m=1;
while(n>m)
{
n-=m;
m++;
}
if(m%2==1)printf("%d/%d",m-n+1,n);
else printf("%d/%d",n,m-n+1);
}