Here you can find the source of divisors(final int n, final int[] buffer)
Parameter | Description |
---|---|
n | a parameter |
buffer | a parameter |
public static int divisors(final int n, final int[] buffer)
//package com.java2s; /*/*from w w w. j a v a 2s. c o m*/ * Copyright 2013 National Bank of Belgium * * Licensed under the EUPL, Version 1.1 or ? as soon they will be approved * by the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * * http://ec.europa.eu/idabc/eupl * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. */ public class Main { /** * * @param n * @return */ public static int[] divisors(final int n) { int[] tmp = new int[1 + n / 2]; int nd = divisors(n, tmp); int[] rslt = new int[nd]; for (int i = 0; i < nd; ++i) rslt[i] = tmp[i]; return rslt; } /** * * @param n * @param buffer * @return */ public static int divisors(final int n, final int[] buffer) { if (n == 1) return 0; int d = 1; int idx = 0; while (d * 2 <= n) { if (n % d == 0) buffer[idx++] = d; ++d; } return idx; } }