Cryptography Reloaded UVALive - 4353(BigInteger)
Posted wtsruvf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cryptography Reloaded UVALive - 4353(BigInteger)相关的知识,希望对你有一定的参考价值。
写写式子就出来了方程。。
然后解方程。。不过数很大。。用Java就好啦。。
就不贴呃的代码了。。。贴别人的。。https://blog.csdn.net/qq_15714857/article/details/49790693?locationNum=5&fps=1
import java.util.*; import java.math.*; public class Main { public static BigInteger sqrt( BigInteger n ) { BigInteger L = BigInteger.ZERO , R = n ; while ( L.compareTo(R) < 0 ) { BigInteger M = L.add(R) ; M = M.divide(BigInteger.valueOf(2)) ; if ( M.multiply(M).compareTo(n) == 0 ) return M ; else if ( M.multiply(M).compareTo(n) > 0 ) R = M.subtract(BigInteger.ONE); else if(M.multiply(M).compareTo(n) < 0) L = M.add(BigInteger.ONE) ; } if ( L.multiply(L).compareTo(n) == 0 ) return L ; else return BigInteger.valueOf(-1) ; } public static void main(String[] args) { Scanner cin = new Scanner(System.in); BigInteger n , d , e ; BigInteger p , q; int kase = 1 ; while(cin.hasNext()){ n = cin.nextBigInteger(); d = cin.nextBigInteger() ; e = cin.nextBigInteger() ; if ( n.compareTo(BigInteger.ZERO) == 0 && d.compareTo(BigInteger.ZERO) == 0 && e.compareTo(BigInteger.ZERO) == 0 ) break ; d = d.multiply(e); d = d.subtract(BigInteger.ONE); int k = 0 ; while(true){ k++ ; BigInteger t = d.mod(BigInteger.valueOf(k)); if ( t.compareTo(BigInteger.ZERO) > 0 ) continue ; t = d.divide(BigInteger.valueOf(k)) ; BigInteger b = (t.subtract(n)).subtract(BigInteger.ONE); BigInteger delta = (b.multiply(b)).subtract(BigInteger.valueOf(4).multiply(n)) ; if ( delta.compareTo(BigInteger.ZERO) >= 0 ) { delta = sqrt(delta) ; if( delta.compareTo(BigInteger.valueOf(-1)) == 0 ) continue ; b = BigInteger.ZERO.subtract(b) ; p = b.add(delta) ; p = p.divide(BigInteger.valueOf(2)) ; q = b.subtract(delta) ; q = q.divide(BigInteger.valueOf(2)) ; if ( p.multiply(q).compareTo(n) == 0 ) { if ( p.compareTo(q) > 0 ) { t = p ; p = q ; q = t ;} System.out.println("Case #"+ kase++ + ": " + p + " " + q); break ; } } } } cin.close(); } }
以上是关于Cryptography Reloaded UVALive - 4353(BigInteger)的主要内容,如果未能解决你的问题,请参考以下文章
css Eric Meyer的CSS Reset Reloaded
ZOJ3781. Paint the Grid Reloaded
Paint the Grid Reloaded(缩点,DFS+BFS)