zoukankan      html  css  js  c++  java
  • Cryptography Reloaded UVALive

    写写式子就出来了方程。。

    然后解方程。。不过数很大。。用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();
        }
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    SQL Server 优化-执行计划
    SQL Server 开发-语法学习
    MySQL管理_数据库常用命令
    MySQL管理_数据库启动与关闭
    SQL Server DBA日常查询视图_数据库性能视图
    SQL Server DBA性能优化
    MySQL系列 | MySQL高级-08逻辑架构
    工具系列 | Docker基本概念
    PHP系列 | [转] PHP中被忽略的性能优化利器:生成器
    PHP系列 | 代码复用trait的构造函数使用
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9328203.html
Copyright © 2011-2022 走看看