-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1. 3D Pyramid.java
More file actions
33 lines (32 loc) · 853 Bytes
/
1. 3D Pyramid.java
File metadata and controls
33 lines (32 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
import java.lang.*;
import java.util.Scanner;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int type = sc.nextInt(), n = sc.nextInt();
int b = 0, s = 0, l = 0;
switch (type){
case 1: while(b <= n){
s++;
b+= s * s;
if(b <= n){
l++;
}
}
break;
case 2: s = 1;
while(b <= n){
b += s * s;
s+=2;
if(b <= n){
l++;
}
}
break;
}
System.out.println(l);
}
}