Advertisement
starcat38

Задача 3

Oct 5th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3.  
  4. public class task3 {
  5.     static int r,a,b,s,h,last,now,i,j;
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         r=sc.nextInt();
  9.         b=r-1;
  10.         a=(int) Math.floor((Math.sqrt(r*r-b*b)));
  11.         s=a*b*4;
  12.         h=b;
  13.         while (true){
  14.             last=now;
  15.             h--;
  16.             now= (int) Math.floor((Math.sqrt(r*r-h*h)));
  17.             if (last==now) break;
  18.             i++;
  19.         }
  20.         h=b;
  21.         for (j=0; j<i; j++){
  22.             h--;
  23.             s+=4*h;
  24.         }
  25.         if (r==2) System.out.println("4");
  26.         else System.out.println(s);
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement