Facebook
From Nam, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 65
  1. import java.util.ArrayList;
  2. public class Nachbar {
  3.  
  4.         public static boolean nachbar(int a, int b) {
  5.                 int k; 
  6.                 ArrayList<Integer> teiler = new ArrayList<Integer>();
  7.                 teiler.add(1);
  8.                 int summe = 0;
  9.                 int i;
  10.                
  11.                         for (k = a-1; k>1; k--) {
  12.                                 if (a % k == 0) {
  13.                                         teiler.add(a / k);
  14.                                 }
  15.                                                        
  16.                         }
  17.                 int teilerlänge = teiler.size();
  18.                                 for (i=0; i< teilerlänge; i++) {
  19.                                         summe = summe + teiler.get(i);
  20.                                 }
  21.                                
  22.                 ArrayList<Integer> teiler2 = new ArrayList<Integer>();
  23.                 teiler2.add(1);
  24.                 int summe2 = 0;
  25.                         for (int f = b-1; f>1; f--) {
  26.                                 if (b % f == 0) {
  27.                                         teiler2.add(b / f);
  28.                                 }
  29.                                                        
  30.                         }
  31.                 int teilerlänge2 = teiler2.size();
  32.                                 for (int u=0; u< teilerlänge2; u++) {
  33.                                         summe2 = summe2 + teiler2.get(u);
  34.                                 }
  35.                                
  36.                 if (a == summe2 && b == summe) {
  37.                  return true;
  38.                 }
  39.                 else {
  40.                         return false;
  41.                 }
  42.  
  43.         }
  44.         public static void obergrenze(int o){
  45.                 for (int p=0; p<o; p++) {
  46.                         for (int j=0; j<o; j++) {
  47.                                 if (nachbar(p,j) == true) {
  48.                                         System.out.println(p +" " + j);
  49.                                 }
  50.                         }
  51.                 }
  52.                
  53.         }
  54.         public static void main(String[] args) {
  55.                 // TODO Auto-generated method stub
  56.                 int a = 220;
  57.                 int b = 284;
  58.                 a = 2;
  59.                 boolean Wahrheit = nachbar(a, b);
  60.                 System.out.println(Wahrheit);
  61.                 int o = 300;
  62.                 obergrenze(o);
  63.                        
  64.                 }
  65.        
  66.        
  67.        
  68. }
  69.