ttaaa

powers kotlin

Dec 7th, 2021
462
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.math.BigInteger
  2. import java.util.*
  3.  
  4. fun main() {
  5.     val n: Int = 100
  6.  
  7.     val start = System.currentTimeMillis()
  8.     val powers: Set<BigInteger> = getPowers(n)
  9.  
  10.     println(powers.size)
  11.     println("TIME: " + ((System.currentTimeMillis() - start) / 1000.0) + "s")
  12. }
  13.  
  14. fun getPowers(n: Int): Set<BigInteger> {
  15.     val generated: MutableSet<BigInteger> = HashSet<BigInteger>()
  16.     for (a in 1..n) {
  17.         for (b in 1..n) {
  18.             generated.add(BigInteger.valueOf(a.toLong()).pow(b))
  19.         }
  20.     }
  21.  
  22.     return generated
  23. }
  24.  
  25.  
RAW Paste Data