UVA Solution 264 - Count on Cantor - Solution in C++ | Volume 2
UVA Online Judge Solution 264 - Count on Cantor | Volume 2
UVA Problem Link - 264 - Count on Cantor https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=200
Problem Name: 264 - Count on Cantor
Problem Number : UVA - 264 - Count on Cantor
Online Judge : UVA Online Judge Solution
Volume: 2
Solution Language : C plus plus
UVA Solution 264 - Count on Cantor Code in CPP:
#include<stdio.h> int main() { int n; while(scanf("%d", &n) == 1) { int i, line, sum = 0; for(i = 1; ; i++) { sum += i; if(sum >= n) { line = i; break; } } printf("TERM %d IS ", n); if(line&1) printf("%d/%d\n", 1+sum-n, line-(sum-n)); else printf("%d/%d\n", line-(sum-n), 1+sum-n); } return 0; }
No comments:
Post a Comment