Commit 60323df0 authored by uiekn's avatar uiekn Committed by uwdkn

Test cases from group 3

parent eac1252a
/**
* Implementation of the sieve of Eratosthenes.
*
* Computes all prime numbers in the interval [2,n], where n is read from stdin.
* Note that System.in.read() returns the ASCII value of the character read!
*/
class Eratosthenes {
public int[] result;
public int count;
public void sieve(int max) {
boolean[] sieve = new boolean[max];
count = 0;
/* Initialize array. */
{
sieve[0] = false;
sieve[1] = false;
int i = 2;
while (i < max) {
sieve[i] = true;
i = i + 1;
}
}
/* Sieve of Eratosthenes algorithm. */
{
int prime = 2;
while (prime < max) {
if (sieve[prime]) {
count = count + 1;
/* Deliberately unoptimized (strength reduction is possible). */
int mult = prime;
while (prime * mult < max) {
sieve[prime * mult] = false;
mult = mult + 1;
}
}
prime = prime + 1;
}
}
result = new int[count];
{
int i = 0;
int j = 0;
while (i < max) {
if (sieve[i]) {
result[j] = i;
j = j + 1;
}
i = i + 1;
}
}
}
public static void main(String[] args) throws Exception {
Eratosthenes e = new Eratosthenes();
int num = System.in.read();
e.sieve(num);
{
int i = 0;
System.out.println(e.count);
while (i < e.count) {
System.out.println(e.result[i]);
i = i + 1;
}
}
}
}
class FloatArithmetic {
public int _2p8;
public int _2p11;
public int _2p16;
public int _2p23;
public int _2p24;
public int _int_min;
public int _f1_5;
public int _fNaN;
public int _seemlinglyArbitraryConstant;
public int _exponentBias;
public void init() {
_2p8 = 256;
_2p11 = 2048;
_2p16 = 65536;
_2p23 = 8388608;
_2p24 = 16777216;
_int_min = -2147483648;
_f1_5 = 1069547520;
_fNaN = -1;
_seemlinglyArbitraryConstant = 1597463007;
_exponentBias = 127;
}
public int buildFloat(int sign, int exponent, int mantissa) {
int result = exponent * _2p23 + mantissa;
if (sign == 1) {
result = negate(result);
}
return result;
}
public int negate(int x) {
return _int_min + x;
}
public int sign(int x) {
if (x >= 0) {
return 0;
} else {
return 1;
}
}
public int exponent(int x) {
if (x < 0) {
x = negate(x);
}
return x / _2p23 % _2p8;
}
public int mantissa(int x) {
if (x < 0) {
x = negate(x);
}
return x % _2p23;
}
public int div2(int x) {
int mantissa = mantissa(x);
int exponent = exponent(x);
if (exponent == 0) {
return 0;
} else {
return buildFloat(sign(x), exponent(x) - 1, mantissa(x));
}
}
public int add(int x, int y) {
int xm = mantissa(x);
int xe = exponent(x);
int xs = sign(x);
int ym = mantissa(y);
int ye = exponent(y);
int ys = sign(y);
int exponentDiff;
int exponent;
int mantissa;
int sign;
int lm;
int sm;
if (xe > ye) {
exponentDiff = xe - ye;
exponent = xe;
sign = xs;
lm = xm;
sm = ym;
} else {
exponentDiff = ye - xe;
exponent = ye;
lm = ym;
sm = xm;
if (xe < ye || xm < ym) {
sign = ys;
} else {
sign = xs;
}
}
lm = lm + _2p23;
sm = sm + _2p23;
while (exponentDiff > 0) {
sm = sm / 2;
exponentDiff = exponentDiff - 1;
}
if (xs == ys) {
mantissa = lm + sm;
} else {
mantissa = lm - sm;
}
if (mantissa / _2p24 == 1) {
mantissa = mantissa / 2;
mantissa = mantissa % _2p23;
exponent = exponent + 1;
} else {
mantissa = mantissa % _2p23;
}
return buildFloat(sign, exponent, mantissa);
}
public int square(int x) {
return mult(x, x);
}
public int mult(int x, int y) {
int xm = mantissa(x);
int xe = exponent(x);
int xs = sign(x);
int ym = mantissa(y);
int ye = exponent(y);
int ys = sign(y);
xm = xm + _2p23;
ym = ym + _2p23;
int xm_lo = xm % _2p11;
int ym_lo = ym % _2p11;
int xm_hi = xm / _2p11;
int ym_hi = ym / _2p11;
int mantissa_lo = xm * ym;
int mantissa_hi = xm_hi * ym_hi
+ xm_hi * ym_lo / _2p11
+ xm_lo * ym_hi / _2p11
+ (xm_lo * ym_hi + xm_lo * ym_hi + mantissa_lo / _2p11) / _2p11;
int exponent = xe + ye - _exponentBias;
int mantissa = mantissa_hi / 2;
if (mantissa / _2p24 == 1) {
mantissa = mantissa / 2;
mantissa = mantissa % _2p23;
exponent = exponent + 1;
} else {
mantissa = mantissa % _2p23;
}
return buildFloat((xs + ys) % 2, exponent, mantissa);
}
public int invSqrt(int num) {
if (num <= 0) {
return _fNaN;
}
int x2 = div2(num);
int y = _seemlinglyArbitraryConstant - num / 2;
y = mult(y, add(_f1_5, negate(mult(x2, square(y)))));
return y;
}
public static void main(String[] args) {
FloatArithmetic ca = new FloatArithmetic();
ca.init();
/*System.out.println(Float.intBitsToFloat(ca.add(1036831949, 1069547520))); // 0.1 + 1.5
System.out.println(Float.intBitsToFloat(ca.add(1065353216, 1069547520))); // 1.0 + 1.5
System.out.println(Float.intBitsToFloat(ca.add(1069547520, 1069547520))); // 1.5 + 1.5
System.out.println(Float.intBitsToFloat(ca.add(1073741824, 1069547520))); // 2.0 + 1.5
System.out.println();
System.out.println(Float.intBitsToFloat(ca.mult(1036831949, 1069547520))); // 0.1 * 1.5
System.out.println(Float.intBitsToFloat(ca.mult(1065353216, 1069547520))); // 1.0 * 1.5
System.out.println(Float.intBitsToFloat(ca.mult(1069547520, 1069547520))); // 1.5 * 1.5
System.out.println(Float.intBitsToFloat(ca.mult(1073741824, 1069547520))); // 2.0 * 1.5
System.out.println();
System.out.println(Float.intBitsToFloat(ca.invSqrt(1036831949))); // 1 / sqrt(0.1)
System.out.println(Float.intBitsToFloat(ca.invSqrt(1065353216))); // 1 / sqrt(1.0)
System.out.println(Float.intBitsToFloat(ca.invSqrt(1069547520))); // 1 / sqrt(1.5)
System.out.println(Float.intBitsToFloat(ca.invSqrt(1073741824))); // 1 / sqrt(2.0)*/
}
}
class Prog1 {
public static void main(String[] args) {
(new Prog1()).test();
}
public boolean test() {
int a = 10;
if(a > 0) if(a > 5) if(a > 10) return true; else return false; else return true;
return false;
}
}
class C1 {
public int x;
}
class C2 {
public C1 x;
}
class TypeError {
public static void main(String[] args) {
boolean b;
C2 obj = new C2();
b = obj.x.x;
}
}
class A {
public int a;
public boolean a;
}
class A {
public void a(int a) { }
public void a() { }
}
class TypeError {
public static void main(String[] args) {
int i = 0;
boolean b = true;
i = true;
i = b;
}
}
class foo {
public foo foo;
public foo foo(foo foo) {
return null;
}
public static void main(String[] args) { }
}
class ShadowField {
public int a;
public static void main(String[] args) {
{
int a;
}
int a;
}
}
class SpecialParamUsage {
public static void main(String[] args) {
int[] args;
}
}
class SpecialParamUsage { class SpecialParamUsage {
public static void main(String[] args) { public static void main(String[] args) {
String[] myArgs = args; args = args;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment