היי,
אני אשמח אם מישהו יעזור לי לפתור את החידה:
http://moadonshay.com/riddles/15/74-pitagurusi
הבנתי שהיא דורשת ידע בתכנות, אבל אני לא מצליח לפתור אותה...
היי,
אני אשמח אם מישהו יעזור לי לפתור את החידה:
http://moadonshay.com/riddles/15/74-pitagurusi
הבנתי שהיא דורשת ידע בתכנות, אבל אני לא מצליח לפתור אותה...
|
|
שמח שהעלת את הבעיה!
בעיה מאוד יפה!
שים לב, שיש טעות בתוצאה למעלה, רשום 7 שלשות שונות, אך למעשה זה 8, כיוון שעשיתי קיצור בסבוכיות, אבדתי תשובה!
למעטה, עשיתי בדיקה וזה הניב לי 16, שהרי ידוע לך שחצי זה תשובות זהות!
הם זהות כיוון שלא אכפת לנו מי זה X ומי זה Y, כלומר, נגיד הפתרון זה שלהם זה:
{30,40,50}, יכול להיות עוד תשובה שזה {40,30,50}, אך לנו אכפת מהמספרים עצמם ולא מהסדר שלהם!
קוד:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { classProgram { staticvoid Main(string[] args) { int i, j, k, count, maxShow = 0, maxNumber = 3; for (k = 3; k <= 1000; k++) { count = 0; for (i = 0; i <= k / 4; i++) { for (j = 0; j <= k / 2; j++) { if ((Math.Pow(i, 2) + Math.Pow(j, 2)) == Math.Pow(k - i - j, 2) && (i > 0) && (j > 0) && (k - i - j) > 0) { count++; //Console.WriteLine("{0}, {1}, {2}", i, j, 120 - i - j); } } } if (maxShow < count) { maxShow = count; maxNumber = k; } } Console.WriteLine("The number is {0}", maxNumber); Console.WriteLine("Is the number of different threes {0}", maxShow); count=0; for (i = 0; i <= 840; i++) { for (j = 0; j <= 840; j++) { if ((Math.Pow(i, 2) + Math.Pow(j, 2)) == Math.Pow(840 - i - j, 2) && (i > 0) && (j > 0) && (840 - i - j) > 0) { count++; Console.WriteLine("{0}, {1}, {2}", i, j, 840 - i - j); } } } Console.WriteLine("{0}", count); } } }
נערך לאחרונה על ידי GanGsTer from mafia; 08-07-2010 בשעה 09:43.
קוד:int max = 0; int maxnum = 0; int c; for (int p = 3; p < 1000; p++) { c = 0; Console.WriteLine(p); for (int i = 1; i <= p-2; i++) { for (int j = 1; j <= p-i-1; j++) { int k=p-j-i; if((k>j)&&(k>i)) if (Math.Pow(k, 2) == Math.Pow(j, 2) + Math.Pow(i, 2)) c++;// c++ ^^} } if (c > max) { max = c; maxnum = p; } } Console.WriteLine(maxnum+": "+max); for (int i = 1; i <= maxnum - 2; i++) { for (int j = 1; j <= maxnum - i - 1; j++) { int k = maxnum - j - i; if ((k > j) && (k > i)) if (Math.Pow(k, 2) == Math.Pow(j, 2) + Math.Pow(i, 2)) Console.WriteLine(i + ":" + j + ":" + k); } }יצא 840 עם 16 שלישיות (כמו 8 רק שיש x,y,z y,x,z)
נערך לאחרונה על ידי SoulSlayer; 29-08-2010 בשעה 17:19.