GithubHelp home page GithubHelp logo

pat's Introduction

浙大PAT题解

准备考研浙大的小菜鸡^_^

PAT A1065

long long的范围为$[-2^{63},2^{63}),$因此题中所给的两个整数相加可能会溢出(正溢出或者负溢出)。

①当$A+B≥2^{63}$时,显然有$A+B>C$成立,但$A+B$会因为超过long long的正向最大值而溢出。题目给定A与B最大值均为$2^{63}-1$,故$A+B$最大为$2^{64}-2$,因此使用long long存储正溢出后的值的区间为$[-2^{63},-2](∵(2^{64}-2) % 2^{64}=-2)$.所以,当$A>0,B>0,A+B<0$时为正溢出,输出true.

②当$A+B<-2^{63}$时,显然有$A+B<C$成立,但$A+B$会因为超过long long的负向最小值而溢出。题目给定A与B最小值均为$-2^{63}$,故$A+B$最小为$-2^{64}$,因此使用long long存储负溢出后的值的区间为$[0,2^{63})(∵(-2^{64})%2^{64}=0)$.所以,当$A<0,B<0,A+B>0$时为负溢出,输出false.

pat's People

Contributors

uranus0205 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.