Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @author Rajat Patel
*/
package patel_rajat;

import java.util.ArrayList;
import java.util.List;

public class Exercises {
public static void main(String... args) {
System.out.println(threeAndFive());
System.out.println(evenFibSum());
}

public static int threeAndFive() {
int s3 = (3 + 999) * 333/2;
int s5_1 = (5 + 995) * 67/2;
int s5_2 = (10 + 985) * 66/2;
return s3+s5_1+s5_2;
}

public static int evenFibSum() {
int sum = 0;
for(int i=0;; i++) {
int curr = fib(i);
if(curr >= 4e6) {
break;
}
if(curr % 2 == 0) {
sum += curr;
}
}

return sum;
}

private static int fib(int n) {
return n < 2 ? n : fib(n-1) + fib(n-2);
}

public static int largestPrimeFactor() {
long n = 600851475143l;
long maxPrime = -1;


while (n % 2 == 0) {
maxPrime = 2;

n /= 2;
}

for (int i = 3; i <= Math.sqrt(n); i += 2) {
while (n % i == 0) {
maxPrime = i;
n = n / i;
}
}

if (n > 2)
maxPrime = n;

return (int) maxPrime;
}

// private static List<Integer> factorize(long num) {
// List<Integer> list = new ArrayList<>();
//
// for(long i=2; i<num; i++) {
// if(num % i == 0) {
// long j = num/i;
// list.addAll(arg0)
// }
// }
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @author Rajat Patel
*/
package patel_rajat;

public class Exercises {
public static void main(String... args) {
System.out.println(threeAndFive());
}

public static int threeAndFive() {
int s3 = (3 + 999) * 333/2;
int s5_1 = (5 + 995) * 67/2;
int s5_2 = (10 + 985) * 66/2;
return s3+s5_1+s5_2;
}

public static int evenFibSum() {
int sum = 0;
for(int i=0;; i++) {
int curr = fib(i);
if(curr >= 4e6) {
break;
}
if(curr % 2 == 0) {
sum += curr;
}
}

return sum;
}

private static int fib(int n) {
return n < 2 ? n : fib(n-1) + fib(n-2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @author Rajat Patel
*/
package patel_rajat;

public class Exercises {
public static void main(String... args) {
System.out.println(threeAndFive());
}

public static int threeAndFive() {
int s3 = (3 + 999) * 333/2;
int s5 = (5 + 995) * 199/2;
return s3+s5;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @author Rajat Patel
*/
package patel_rajat;

public class Exercises {
public static void main(String... args) {
System.out.println(threeAndFive());
}

public static int threeAndFive() {
int s3 = (3 + 999) * 333/2;
int s5_1 = (5 + 995) * 67/2;
int s5_2 = (10 + 985) * 66/2;
return s3+s5_1+s5_2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @author Rajat Patel
*/
package patel_rajat;

public class Exercises {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @author Rajat Patel
*/
package patel_rajat;

import java.util.ArrayList;
import java.util.List;

public class Exercises {
public static void main(String... args) {
System.out.println(threeAndFive());
System.out.println(evenFibSum());
System.out.println(largestPrimeFactor());
}

public static int threeAndFive() {
int s3 = (3 + 999) * 333/2;
int s5_1 = (5 + 995) * 67/2;
int s5_2 = (10 + 985) * 66/2;
return s3+s5_1+s5_2;
}

public static int evenFibSum() {
int sum = 0;
for(int i=0;; i++) {
int curr = fib(i);
if(curr >= 4e6) {
break;
}
if(curr % 2 == 0) {
sum += curr;
}
}

return sum;
}

private static int fib(int n) {
return n < 2 ? n : fib(n-1) + fib(n-2);
}

public static int largestPrimeFactor() {
long n = 600851475143l;
long maxPrime = -1;


while (n % 2 == 0) {
maxPrime = 2;

n /= 2;
}

for (int i = 3; i <= Math.sqrt(n); i += 2) {
while (n % i == 0) {
maxPrime = i;
n = n / i;
}
}

if (n > 2)
maxPrime = n;

return (int) maxPrime;
}

// private static List<Integer> factorize(long num) {
// List<Integer> list = new ArrayList<>();
//
// for(long i=2; i<num; i++) {
// if(num % i == 0) {
// long j = num/i;
// list.addAll(arg0)
// }
// }
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package patel_rajat;

public class Exercises {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @author Rajat Patel
*/
package patel_rajat;

public class Exercises {
public static void main(String... args) {
System.out.println(threeAndFive());
System.out.println(evenFibSum());
}

public static int threeAndFive() {
int s3 = (3 + 999) * 333/2;
int s5_1 = (5 + 995) * 67/2;
int s5_2 = (10 + 985) * 66/2;
return s3+s5_1+s5_2;
}

public static int evenFibSum() {
int sum = 0;
for(int i=0;; i++) {
int curr = fib(i);
if(curr >= 4e6) {
break;
}
if(curr % 2 == 0) {
sum += curr;
}
}

return sum;
}

private static int fib(int n) {
return n < 2 ? n : fib(n-1) + fib(n-2);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LaunchTargetManager/org.eclipse.launchbar.core.launchTargetType.local,Local/arch=x86_64
LaunchTargetManager/org.eclipse.launchbar.core.launchTargetType.local,Local/os=win32
configDescList=org.eclipse.launchbar.core.descriptorType.default\:Exercises
eclipse.preferences.version=1
org.eclipse.launchbar.core.descriptorType.default\:Exercises/activeLaunchMode=run
org.eclipse.launchbar.core.descriptorType.default\:Exercises/activeLaunchTarget=org.eclipse.launchbar.core.launchTargetType.local\:Local
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/Branching-Assignment/src/patel_rajat/Exercises.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="patel_rajat.Exercises"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Branching-Assignment"/>
</launchConfiguration>
13 changes: 13 additions & 0 deletions .metadata/.plugins/org.eclipse.debug.ui/dialog_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<section name="Workbench">
<section name="org.eclipse.debug.ui.SCOPED_SAVE_SELECTION_DIALOG">
<item value="309" key="DIALOG_WIDTH"/>
<item value="1|Segoe UI|9.0|0|WINDOWS|1|-12|0|0|0|400|0|0|0|1|0|0|0|0|Segoe UI" key="DIALOG_FONT_NAME"/>
<item value="377" key="DIALOG_HEIGHT"/>
</section>
<section name="org.eclipse.debug.ui.SELECT_LAUNCH_SHORTCUT_DIALOG">
<item value="270" key="DIALOG_WIDTH"/>
<item value="1|Segoe UI|9.0|0|WINDOWS|1|-12|0|0|0|400|0|0|0|1|0|0|0|0|Segoe UI" key="DIALOG_FONT_NAME"/>
<item value="436" key="DIALOG_HEIGHT"/>
</section>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchHistory>
<launchGroup id="org.eclipse.jubula.launch.ui.launchGroup.aut">
<mruHistory>
<launch memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;launchConfiguration local=&quot;true&quot; path=&quot;Exercises&quot;/&gt;&#13;&#10;"/>
</mruHistory>
<favorites/>
</launchGroup>
<launchGroup id="org.eclipse.debug.ui.launchGroup.profilee">
<mruHistory/>
<favorites/>
</launchGroup>
<launchGroup id="org.eclipse.debug.ui.launchGroup.profile">
<mruHistory/>
<favorites/>
</launchGroup>
<launchGroup id="org.eclipse.debug.ui.launchGroup.debug">
<mruHistory>
<launch memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;launchConfiguration local=&quot;true&quot; path=&quot;Exercises&quot;/&gt;&#13;&#10;"/>
</mruHistory>
<favorites/>
</launchGroup>
<launchGroup id="org.eclipse.ui.externaltools.launchGroup">
<mruHistory/>
<favorites/>
</launchGroup>
<launchGroup id="org.eclipse.debug.ui.launchGroup.run">
<mruHistory>
<launch memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;launchConfiguration local=&quot;true&quot; path=&quot;Exercises&quot;/&gt;&#13;&#10;"/>
</mruHistory>
<favorites/>
</launchGroup>
</launchHistory>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading