math

Why we can use sqrt(n) instead of n/2 as an upper bound while finding prime numbers? [duplicate]

纵然是瞬间 提交于 2021-02-05 09:29:06
问题 This question already has answers here : Why do we check up to the square root of a prime number to determine if it is prime? (13 answers) Closed 7 years ago . How we can use sqrt(n) instead of n/2 in this code? Is it correct to use sqrt(n) ? static boolean isPrime(long n) { if(n<=1) return false; double limit = Math.sqrt(n); for(long i = 2; i <= limit; i++) { if(n%i==0) return false; } return true; } 回答1: if n is not a prime, say n = p * q , then p and q cannot be both greater than sqrt(n)

Why we can use sqrt(n) instead of n/2 as an upper bound while finding prime numbers? [duplicate]

谁都会走 提交于 2021-02-05 09:28:10
问题 This question already has answers here : Why do we check up to the square root of a prime number to determine if it is prime? (13 answers) Closed 7 years ago . How we can use sqrt(n) instead of n/2 in this code? Is it correct to use sqrt(n) ? static boolean isPrime(long n) { if(n<=1) return false; double limit = Math.sqrt(n); for(long i = 2; i <= limit; i++) { if(n%i==0) return false; } return true; } 回答1: if n is not a prime, say n = p * q , then p and q cannot be both greater than sqrt(n)

Obtaining the Uni-variate 95% confidence interval between two variables (MATLAB)

这一生的挚爱 提交于 2021-02-05 09:25:08
问题 I have Matrix A [1000,1] of variable A readings at 1000 locations, I also have Matrix B [1000,1] of variable B readings at the same 1000 locations as Variable A. I obtained the regression coefficient using the regress function and now I want to know if my regression coefficient passes the Uni-variate 95% confidence interval using Students t distribution. But I am finding it difficult 来源: https://stackoverflow.com/questions/62182588/obtaining-the-uni-variate-95-confidence-interval-between-two

Moving decimal from the right in PHP

落爺英雄遲暮 提交于 2021-02-05 09:23:09
问题 I have large numbers and their decimals points. Here are some examples and what should return: Number: 300000 Decimals: 8 Should return: 0.00300000 Number: 700000000 Decimals: 8 Should return: 7 Number: 800000000 Decimals: 6 Should return: 800 At the moment I'm doing this: substr($number, 0, abs($decimals + 1)) But it returns 0 if the number of decimals is superior to the number of digits in the number (example one returns 0). Any idea how to do this? 回答1: Divide by 10 to the power of the

How to fix 'ValueError: math domain error' in python?

╄→гoц情女王★ 提交于 2021-02-05 08:53:07
问题 I am trying to write a program which calculates formula y=√x*x + 3*x - 500, Interval is [x1;x2] and f.e x1=15, x2=25. I tried to use Exception Handling but it didn't help. And the code I try to use now gives me: ValueError: math domain error import math x1 = int(input("Enter first number:")) x2 = int(input("Enter second number:")) print(" x", " y") for x in range(x1, x2): formula = math.sqrt(x * x + 3 * x - 500) if formula < 0: print("square root cant be negative") print(x, round(formula, 2))

Round div height to the nearest even number if it has an odd value

天大地大妈咪最大 提交于 2021-02-05 08:47:08
问题 Basically I want to use transformY but the subpixel blur is very annoying and only occurs when the div is an odd height. As the height depends on the text viewport etc, need this to be flexible so realistically need it to get the height of the div - Divide it by 2, round to the nearest number then x 2 so it'd always produce an even value. 回答1: The question is old, but it's the first answer on google for "rounding div height to even number", so it might help others. You have perfectly

How many A records can fit in a single DNS response?

烈酒焚心 提交于 2021-02-05 08:27:29
问题 What are the size limits on DNS responses? For instance how many 'A' resource records can be present in a single DNS response? The DNS response should still be cache-able. 回答1: The largest guaranteed supported DNS message size is 512 bytes. Of those, 12 are used up by the header (see §4.1.1 of RFC 1035). The Question Section appears next, but is of variable length - specifically it'll be: the domain name (in wire format) two bytes each for QTYPE and QCLASS Hence the longer your domain name is

Check if cyclic (modulo 16) number is larger than another?

跟風遠走 提交于 2021-02-05 07:40:39
问题 I have two a cyclic integer, modulo 16, so they assume values between 0 and 15. I need to compare two numbers to determine if n_1 is greater than n_0 n_1 > n_0 Obviously, this is not exactly defined, so I define n_1 to be greater than n_0 if it is less than 8 "numbers" ahead, otherwise, it is lesser than n_0 (if not equal). I.e. if: n_0 = 0 if n_1 is between 1 and 8 (both inclusive) then n_1 is greater than n_0. n_0 = 5 if n_1 is between 6 and 15 (both inclusive) then n_1 is greater than n_0.

Check if cyclic (modulo 16) number is larger than another?

一曲冷凌霜 提交于 2021-02-05 07:39:41
问题 I have two a cyclic integer, modulo 16, so they assume values between 0 and 15. I need to compare two numbers to determine if n_1 is greater than n_0 n_1 > n_0 Obviously, this is not exactly defined, so I define n_1 to be greater than n_0 if it is less than 8 "numbers" ahead, otherwise, it is lesser than n_0 (if not equal). I.e. if: n_0 = 0 if n_1 is between 1 and 8 (both inclusive) then n_1 is greater than n_0. n_0 = 5 if n_1 is between 6 and 15 (both inclusive) then n_1 is greater than n_0.

Java: why does multiplying large positive number cause negative results? [duplicate]

匆匆过客 提交于 2021-02-05 07:35:43
问题 This question already has answers here : why Integer.MAX_VALUE + 1 == Integer.MIN_VALUE? (8 answers) Closed 1 year ago . I’m seeing some strange behavior multiplying integers with Java. I was doing some coding exercises and came upon the following fizz buzz type of exercise. The requirements: Given an integer, write a function that finds the product of every multiple of 3 which is smaller than the given integer, except any multiple of 5. Eg, given 17 we want to return 12*9*6*3 (= 1944). I