#25714: 簡單的寫法C++


qwe638853@gmail.com (bang)

School : No School
ID : 104014
IP address : [122.117.22.72]
Last Login :
2021-08-01 23:03:36
c031. 00264 - Count on Cantor -- UVa264 | From: [114.33.13.87] | Post Date : 2021-06-16 10:20

#include<bits/stdc++.h>

using namespace std;

 

int main(){

int n;

while(cin>>n){

int i=1,sum=0;

while(1){

sum += i;

if(sum>=n)break;

i++;

}

int l=i,r=1;

sum -= n;

if(i%2==0){

cout<<"TERM "<<n<<" IS "<<l-sum<<"/"<<r+sum<<endl;

}else{

cout<<"TERM "<<n<<" IS "<<r+sum<<"/"<<l-sum<<endl;

}

 

}

return 0;

}

 
ZeroJudge Forum