import java.io.*;
class Main {
private static int jinwoo;
private static int sunwoo;
public static void distribution(boolean dayChk) {
if (dayChk) {
sunwoo = (jinwoo % 2 == 0) ? (sunwoo + jinwoo / 2) : ((sunwoo + jinwoo / 2) + 1);
jinwoo = jinwoo / 2;
} else {
jinwoo = (sunwoo % 2 == 0) ? (jinwoo + sunwoo / 2) : ((jinwoo + sunwoo / 2) + 1);
sunwoo = sunwoo / 2;
}
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] temp = br.readLine().split(" ");
jinwoo = Integer.parseInt(temp[0]);
sunwoo = Integer.parseInt(temp[1]);
int day = Integer.parseInt(br.readLine());
boolean startDayBool = true;
for (int i = 0; i < day; i++) {
distribution(startDayBool);
startDayBool = !startDayBool;
}
System.out.println(jinwoo + " " + sunwoo);
}
}
import java.io.*;
class Main {
public static int recursiveRemainCharNumber() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] temp = br.readLine().split(" ");
int characterNumber = Integer.parseInt(temp[0]);
int holdingTime = Integer.parseInt(temp[1]);
String[] characters = br.readLine().split(" ");
int remainCharNumber = 1;
for (int i = 0; i <characterNumber - 1; i++) {
if ((Integer.parseInt(characters[i + 1]) - Integer.parseInt(characters[i])) > holdingTime) {
remainCharNumber = 1;
} else {
remainCharNumber++;
}
}
return remainCharNumber;
}
public static void main(String[] args) throws IOException {
int remainCharNumber = recursiveRemainCharNumber();
System.out.println(remainCharNumber);
}
}
시그마 공식 세제곱으로 접근해서 해결해야 한다
반복문으로 코드 작성하면 실행 시간에 부하 발생
import java.io.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long diceNumber = Integer.parseInt(br.readLine());
long sum = diceNumber * (diceNumber + 1) / 2 % 1000000007L;
long result = sum * sum % 1000000007L;
System.out.println(result);
}
}