(暴力枚举)UVa10976FractionsAgain?!
题目:
输入一个k,让你求得所有的满足 1/k = 1/x + 1/y 的情况,并且打印出来 。
分析:
这是一道简单暴力枚举的题目。
枚举对象: y (x可以根据k和y直接得出)
枚举范围: [ k + 1 , 2 * k]
判断条件: 之前的想法是( int ) ( 1.0 / (1.0 / k - 1.0 / y ) ) ==(1.0 /(1.0 /k-1.0 /y) ) // 当x为整数的时候满足条件,打印出来 。
后来想想这种精确度的东西肯定会出问题,所以还是不用这个了。
模拟分数之间的减法 当 ( k * y ) % ( y - k ) == 0 // 同样是说明了x的分子为1,即x为整数。
实现代码:
#include <iostream>
using namespace std;
int xHub[10010];
int yHub[10010];
int main( int argc, char const *argv[] ) {
int k;
while ( cin >> k ) {
int maxn = k << 1;
int count = 0;
for (int y = k + 1; y <= maxn; y++) {
if ( (k * y ) % ( y - k ) == 0 ) {
xHub[count] = (k * y ) / ( y - k );
yHub[count++] = y;
}
}
cout << count << endl;
for ( int i = 0; i < count; ++i ) {
cout << "1/" << k << " = 1/" << xHub[i] << " + 1/" << yHub[i] << endl;
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。By PengCoX ( Pengc825@foxmail.com )
分享到:
相关推荐
Neverending Fractions: An Introduction to Continued Fractions
As continued fractions become more important again, in part due to their use in finding algorithms in approximation theory, this timely book revives the approach of Wallis, Brouncker and Euler and ...
这本数学书里面有很多连分数公式 是一本好书This book is aimed at two kinds of readers: firstly, people working in or near mathematics, who are curious about continued fractions; and secondly, senior or ...
As continued fractions become more important again, in part due to their use in finding algorithms in approximation theory, this timely book revives the approach of Wallis, Brouncker and Euler and ...
Special functions are pervasive in all ... We emphasise that only 10% of the continued fractions contained in this book, can also be found in the Abramowitz and Stegun project or at the Wolfram website!
作者: Oleg Karpenkov 出版社: Springer ISBN: 9783642393679
资源来自pypi官网。 资源全名:binary_fractions-1.0.2.tar.gz
Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal representation has a repeating ...
Continued fractions and Pade approximants C. Brezinski
这是本关于连分数的数学文献 这本书里面有很多连分数公式L. Lorentzen and H. Waadeland, “Continued Fractions with Applications,” North Holland, Amsterdam, 1992.
the most recent developments in solving the celebrated 1812 Gauss' problem which originated the metrical theory of continued fractions. At the same time, they study exhaustively the Perron-Frobenius ...
Continued fractions C. D Olds美国新数学丛书《连分数》的英文原版
This book is aimed at two kinds of readers: firstly, people working in or near mathematics, who are curious about continued fractions; and secondly, senior or graduate students who would like an ...
一个简单的程序,通过为每个枚举的有理数分配一个唯一的自然数作为标签来证明有理数是可数的。 理论/资料来源 程序的基本功能依赖于一系列函数,在所有自然数N到所有有理数Q之间都有明确的双射。 程序利用该双射来...
Manhattan GMAT Math-Fractions, Decimals & Percents.pdf
" https://www.random.org/decimal-fractions/?num=1&dec=9&col=1&format=plain " ; Async .start(seq() { // concurrently request for 10 random numbers var numberTasks = Seq .range( 0 , 10 ) | > Seq ....
连分式与A、B型错排多项式,刘丽,,本文,我们统一地给出了A、B型错排多项式的一般发生函数的连分式展开。我们的证明是基于它们的指数发生函数及指数Riordan阵理论。
Attachment B Models for Dividing Fractions 附件 B 分数除法模型.doc
Continued fractions require a thought process that is different from many others, yet do not require sophisticated mathematics. Generally speaking, the more different types of mathematical thinking ...
Periodic continued fractions are well understood. We can determine when they converge, when they diverge, their values if they converge and the asymptotic behavior of their tail sequences. Indeed, it ...