2010年9月17日 星期五

ACM 10408 - Farey sequences

#include <stdio.h>
int main()
{
unsigned int n, term;
while (scanf("%d %d", &n, &term) == 2)
{
int a = 0, b = 1, c = 1, d = n, e, f, k;
unsigned int i = 0;
while (++i != term)
{
k = (int)((n + b) / (float)d);
e = k * c - a;
f = k * d - b;
a = c; b = d; c = e; d = f;
}
printf("%d/%d\n", c, d);
}
return 0;
}


回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...