Tags
 IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6

# Fast formula to get the range a number is in, given a perfect binary subdivision?

By : Brooke
Date : September 16 2020, 09:00 PM
I wish did fix the issue. Mind the set of positive integers from 0 til L exclusive. For any positive integer n up to log2(K), can split the set in 2^n consecutive subsets of equal length. For example, for L = 256, n = 3, we'd get 2^3, or 8, subsets: {0..31}, {32..63}, {64..95}, {96..127}, {128..160}, {160..191}, {192..223}, {224..255}. , This works:
code :
``````#include <stdio.h>

typedef struct { int a, b; } pair;

pair f(int L, int n, int i) {
int len = L / (1 << n);
int a = i / len * len;
return (pair) { a, a + len - 1 };
}

int main() {
pair p = f(256, 3, 100);
printf("%d %d\n", p.a, p.b);
}
``````
``````#include <stdio.h>
#include <math.h>

typedef struct { double a, b; } paird;

paird fd(double L, double n, double i) {
double len = L / pow(2, n);
double a = 0, b;
while (b = a + len, b < i) {
a = b;
}
return (paird){ a, b };
}

int main() {
paird p = fd(127, 7, 100);
printf("%f %f\n", p.a, p.b); // (99.218750, 100.210938)
}
``````

Share :

## For an Excel Formula's variable taking a Range, input row number by the result of a formula

By : Nazeer
Date : March 29 2020, 07:55 AM
Hope this helps I'm trying to fill in this =SERIES function to populate a line plot in Excel 2007. , This can be done using INDEX to specify the range
code :
``````\$BB\$2:INDEX(\$BB:\$BB,COUNTA(\$BB:\$BB)+1)
``````
``````OFFSET(\$BB\$2,0,0,COUNTA(\$BB:\$BB))
``````
``````\$BB\$2:INDIRECT("BB"&COUNTA(\$BB:\$BB)+1)
``````

## Calculate number of perfect squares in a given big range in C

By : Coronel Fernando Car
Date : March 29 2020, 07:55 AM
this one helps. If you just need to count how many perfect squares there are between 1..N all you need to do is: take a square root of N and get its integer value :)
Just think about it. For the range 1..10 the correct answer is 3 (1, 4, 9) which is, incidentally, the rounded-down sqrt(10). If you don't want to count 1 as a perfect square - fine, just don't count it.
code :
``````(int)sqrt(N) - (int)sqrt(M) - 1
``````

## Perfect Number Method w/ Range

By : Audi
Date : March 29 2020, 07:55 AM
hop of those help? You can't put an else statement inside and if statement unless there is another if statement there.
Here is the whole code. Also you weren't reading in all the numbers entered. The first for loop should be n1 <= endval; and not n1 < endval; so that it also checks the enval entered.
code :
``````    Scanner scanner = new Scanner(System.in);
int counter = 0;

System.out.println("\nPerfect Number Finder Program");

System.out.print("\nEnter the start value: ");
int starval = scanner.nextInt();
System.out.print("Enter the end value:");
int endval = scanner.nextInt();

for (int n1 = starval; n1 <= endval; n1++) {
int sum = 0;
for (int n2 = 1; n2 < n1; n2++) {
if (n1 % n2 == 0) {
sum = sum + n2;
}
}

if (sum == n1) {
System.out.println(n1 + " is a perfect number");
counter ++; //This will add one to the counter if this loop is enterd
}
if(n1 == endval){
System.out.println("FINISHED!");
break;
}
}
//If the counter is 0 then it will display the message
if(counter == 0){
System.out.println("THERE IS NO PERFECT NUMBERS");
}
}
``````

## Calculating the number of perfect squares, perfect cubes,etc in a given range?

By : LdoZ
Date : March 29 2020, 07:55 AM
wish of those help Float numbers calculations are not exact.
64**1/3 could have value like ~3.99999975, so floor gives 3. Or 4.000000016, so ceil gives 5 (I did not check real value). You must take numerical errors into account.

## Not counting number of perfect numbers within a range?

By : nyron waite
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I want to find the number of the perfect numbers in a range. This is what i have done so far. , Need to make sum=0 for every input. For e.g
code :
``````if(sum == i) {
count++;
}
sum = 0; /* add this line here */
``````
``````for(int i=x;i<=y;i++) {
sum = 0; /* or make sum as 0 here  */
for(int j=1; j<i; j++) {
if(i%j == 0) {
sum=sum+j;
}
}
if(sum == i) {
count++;
}
}
``````