← Playground

Update adventOfCode20.cpp

212cfdff69a29276111c59859bfe3afdcf02d03a · darakna · Jan 15, 2016 16:18

+8 −13 · 1 file changed

  • adventOfCode20.cpp +8 −13
diff --git a/adventOfCode20.cpp b/adventOfCode20.cpp
index 0ac0c76..83eb8ef 100644
--- a/adventOfCode20.cpp
+++ b/adventOfCode20.cpp
@@ -1,11 +1,7 @@
-// AoCD20.cpp : Defines the entry point for the console application.
-//
-
 #include "stdafx.h"
 #include<iostream>
 #include<string>
 #include<cstdint>
-
 int main()
 {
 	int64_t present = 36000000;
@@ -13,28 +9,27 @@ int main()
 	int64_t found = 0;
 	while (found == 0)
 	{
-		for (int64_t casa = 1; casa <= present; casa++)
+		for (int64_t casa = 1; casa <= present; casa=casa+1)
 		{
 			curent_pres = 0;
 			for (int64_t ren = 1; ren <= casa; ren++)
 			{
 				if (casa % ren == 0)
 				{
-
 					curent_pres = curent_pres + ren * 10;
-					if (curent_pres == present)
+					if (curent_pres >= present)
 					{
 						std::cout << casa << std::endl;
+						found = 1;
+						ren = casa;
+						casa = present;
 						break;
 					}
 				}
 			}
-			std::cout << "House " << casa << " got " << curent_pres << " presents." << std::endl;
-
+			if((casa % 1000 == 0) || (found == 1))std::cout << "House " << casa << " got " << curent_pres << " presents." << std::endl;
 		}
-
 	}
-	
-    return 0;
-}
 
+	return 0;
+}