Skip to content
This repository has been archived by the owner on Oct 5, 2020. It is now read-only.

Solution of project euler problem 1 in java #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
24 changes: 24 additions & 0 deletions coder07/ProjectEuler#1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int a0 = 0; a0 < t; a0++){
long N = in.nextInt();
long n=N-1;
long n3=n/3;
long s=n3*(3+(n3*3))/2;
long n5=n/5;
long s1=n5*(5+(n5*5))/2;
long n15=n/15;
long s2=n15*(15+(n15*15))/2;
System.out.println(s+s1-s2);
}
}
}
29 changes: 29 additions & 0 deletions coder07/ProjectEuler#2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int a0 = 0; a0 < t; a0++){
long n = in.nextLong();
long a=1,b=2,c,sum=2;
while(true)
{
c=a+b;
a=b;
b=c;
if(c>=n)
break;
if(c%2==0)
sum+=c;
}
System.out.println(sum);

}
}
}