Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.*;
- import java.util.*;
- import java.io.*;
- public class Main {
- static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
- static PrintWriter out = new PrintWriter(System.out);
- static String randomStr(){
- Random rand = new Random();
- int len = rand.nextInt(150) + 1;
- String res = "";
- for (int i=0;i<len;i++){
- res += (char)('0' + rand.nextInt(10));
- }
- return res;
- }
- static void solve(){
- BigDecimal b = new BigDecimal(in.nextToken());
- BigDecimal L = BigDecimal.ZERO;
- BigDecimal R = b;
- BigDecimal ten = new BigDecimal("0.000000000000001");
- BigDecimal two = BigDecimal.valueOf(2);
- while ((R.subtract(L)).compareTo(ten) > 0) {
- BigDecimal mid = (L.add(R)).divide(two, 20, BigDecimal.ROUND_HALF_EVEN);
- if (((mid.multiply(mid)).multiply(mid)).compareTo(b) <= 0){
- L = mid;
- } else {
- R = mid;
- }
- }
- L = L.setScale(13, BigDecimal.ROUND_HALF_UP);
- L = L.setScale(10, BigDecimal.ROUND_FLOOR);
- String s = L.toString();
- int sum = 0;
- for (int i=0;i<s.length();i++){
- char ch = s.charAt(i);
- if ('0' <= ch && ch <= '9') {
- sum += ch - '0';
- }
- sum %= 10;
- }
- out.println(sum + " " + s);
- }
- public static void main(String[] args) {
- int t = in.nextInt();
- for (int i=0;i<t;i++){
- solve();
- }
- out.close();
- }
- }
- class Pair<F, S> {
- public final F first;
- public final S second;
- public Pair(F first, S second) {
- this.first = first;
- this.second = second;
- }
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof Pair)) {
- return false;
- }
- Pair<?, ?> p = (Pair<?, ?>) o;
- return Objects.equals(p.first, first) && Objects.equals(p.second, second);
- }
- @Override
- public int hashCode() {
- return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
- }
- public static <A, B> Pair <A, B> create(A a, B b) {
- return new Pair<A, B>(a, b);
- }
- }
- class FastReader {
- BufferedReader bf;
- StringTokenizer tk = null;
- String DELIM = " ";
- public FastReader(BufferedReader bf) {
- this.bf = bf;
- }
- public void skipLine(){
- try {
- bf.readLine();
- } catch (Exception e) {
- throw new RuntimeException();
- }
- }
- public String nextToken() {
- while (tk==null || !tk.hasMoreTokens()) {
- try {
- tk = new StringTokenizer(bf.readLine(), DELIM);
- } catch (Exception e){
- throw new RuntimeException();
- }
- }
- return tk.nextToken();
- }
- public int nextInt() {
- try {
- return Integer.parseInt(nextToken());
- } catch (Exception e) {
- throw new RuntimeException();
- }
- }
- public long nextLong() {
- try {
- return Long.parseLong(nextToken());
- } catch (Exception e) {
- throw new RuntimeException();
- }
- }
- public double nextDouble() {
- try {
- return Double.parseDouble(nextToken());
- } catch (Exception e) {
- throw new RuntimeException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement