結果
問題 | No.491 10^9+1と回文 |
ユーザー |
|
提出日時 | 2017-03-23 23:28:08 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 142 ms / 1,000 ms |
コード長 | 882 bytes |
コンパイル時間 | 3,936 ms |
コンパイル使用メモリ | 77,600 KB |
実行使用メモリ | 54,364 KB |
最終ジャッジ日時 | 2024-10-01 08:40:02 |
合計ジャッジ時間 | 20,190 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 103 |
ソースコード
import java.util.Scanner;public class Kaibun {public static void main(String[] args) throws InterruptedException {Scanner s = new Scanner(System.in);long t = (long)Math.pow(10, 9) +1 , N = s.nextLong();s.close();int end = (int)(N/t);long count = 0, stock = 0;int keta = Integer.toString(end).length();if(keta == 1){count = end;}else{stock = 9;for(int i = 1;i < keta;i++){count += stock;if(i%2 == 0){stock *= 10;}}int k = (int)Math.pow(10, keta/2);count += ((end - (int)Math.pow(10,keta-1))/k+1);StringBuilder str = new StringBuilder(Integer.toString(end/k));String str2 = str.toString();if(keta%2 == 1){str.deleteCharAt(str.length()-1);}str2 = str2.concat(str.reverse().toString());if(Integer.parseInt(str2) > end){count--;}}System.out.println(count);}}