AtCoder ABC 106 A&B&C
A問題
- 縦横からそれぞれ-1して算出
private void solveA() {
Scanner scanner = null;
int numA = 0;
int numB = 0;
try {
scanner = new Scanner(System.in);
numA = scanner.nextInt();
numB = scanner.nextInt();
System.out.println((numA - 1) * (numB - 1));
System.out.println("");
} finally {
if (scanner != null) {
scanner.close();
}
}
}
B問題
- その数の約数を全て調べる
private void solveB2() {
Scanner scanner = null;
int numN = 0;
try {
scanner = new Scanner(System.in);
numN = scanner.nextInt();
int count = 0;
/*
* 1からNまでの数値を全探索
*/
for (int i = 1; i <= numN; i++) {
if (i % 2 == 0) {
continue;
}
int wkRes = 0;
/*
* 数値iが、約数をいくつ持つのか調べる
* 最大でもNまで(i<=Nだし)
* 自身も約数だということを忘れずに
*/
for (int j = 1; j <= numN; j++) {
if (j % 2 == 0) {
continue;
}
if (i % j == 0) {
wkRes++;
}
}
if (wkRes == 8) {
count++;
}
}
System.out.println(count);
} finally {
if (scanner != null) {
scanner.close();
}
}
}
C問題
- $1$は$5000兆日後$も$1$のままだが、$2$は$2^{5000兆}$となるので計算は無理
- 文字列がK番目まですべて$1$なら$5000兆日後$もK番目は$1$だけど、その間に$2以上の数値$が入っていればその数値になる
- 文字列を$K番目$まで調べていって、$1$以外が出現したらその数値が$5000兆日後$の$K番目$
- $1$のみだったら$5000兆日後$の$K番目$は$1$
private void solveC() {
Scanner scanner = null;
String wkS;
long count = 0;
try {
scanner = new Scanner(System.in);
wkS = scanner.next();
count = scanner.nextLong();
String wk = wkS;
if (count <= wkS.length()) {
wk = wkS.substring(0, (int) count);
}
for (int i = 0; i < wk.length(); i++) {
if (wk.charAt(i) != '1') {
System.out.println(wk.charAt(i));
return;
}
}
System.out.println(1);
} finally {
if (scanner != null) {
scanner.close();
}
}
}