Exemple #1
0
int main(int argc, char** argv)
{
  clock_t begin = clock();

  std::vector<int> dvec;
  for(int i=1; i<=1000; i++)
  {
    double sqrted = sqrt( i);
    if( sqrted != ceil(sqrted)) {
      dvec.push_back(i); 
    }
  }
  cout << "dvec.size()=" << dvec.size() << endl;

  BigInt maxX(0);
  int atD;

  //for(int i=0; i<dvec.size(); i++)
  for(int i=0; i<1; i++)
  {
//    int di = dvec[i];
    int di = 7;

    cout << "di=" << di << endl;
    int seq=0;
    Fraction first = getFirstFraction( di);
    first.print(); cout << endl;
    Fraction next = first.copy();
    while( true)
    {
      seq++;
      next = next.getRationalized();
      next = next.getConversed();
      next.print(); cout << endl;

      // 이렇게 다음 연분수를 구해나가긴 하지만, 
      // 여기서 내가 관심있는 것은.. 분자/분모 로 이뤄진, 유리 근사값임.
      // if approximate fraction 'denominator, numerator' meets equation
      // equation solved. break!

      if( seq > 1000) break;
    }

    // get Convergent SquareRoot(di) while convergent x,y meets x^2 - Dy^2 = 1
    //BigInt x = convergent_until_equation_solved( di ); 
  }

  cout << "maxX = " << maxX.toString() << " at d=" << atD << endl;

  clock_t end = clock();
  std::cout << "elapsed time=" << double( end-begin) / CLOCKS_PER_SEC << endl;
}
Exemple #2
0
int main(int argc, char** argv)
{
	clock_t begin = clock();
	
	/* starting code */
/*
	Fraction f0 = getFirstFraction(23);
	f0.print(); cout << endl;
	Fraction rf0 = f0.getRationalized();
	rf0.print(); cout << endl;

	Fraction f1; f1 = rf0.getConversed();
	f1.print(); cout << endl;
	Fraction rf1 = f1.getRationalized();
	rf1.print(); cout << endl;
	*/

	int oddcnt = 0;
	for(int i=1; i<=10000; i++)
	{
		if( sqrt(i) == floor( sqrt(i))) { continue; }
		
		Fraction first = getFirstFraction( i);
		int firstN = first.getn();

		int seq = 0;
		Fraction next = first.copy();
		while( true) {
			seq++;
			next = next.getRationalized();
			next = next.getConversed();
			if (next.hasSameFractionWith( first)) { break; }
		}
//		cout << "i=" << i << " seq=" << seq << endl;
		if( seq%2 == 1) { oddcnt++; }
	}

	cout << "oddcnt = " << oddcnt << endl;
	/* end of code */
	clock_t end = clock();
	std::cout << "elapsed time=" << double(end - begin) / CLOCKS_PER_SEC << std::endl;
	return 0;
}