{"id":7,"date":"2011-03-31T18:09:38","date_gmt":"2011-03-31T12:09:38","guid":{"rendered":"http:\/\/ujjalruet.wordpress.com\/?p=6"},"modified":"2011-03-31T18:09:38","modified_gmt":"2011-03-31T12:09:38","slug":"big-number-problem-in-java-in-programming-contest","status":"publish","type":"post","link":"https:\/\/blog.ujjal.net\/?p=7","title":{"rendered":"Big Number problem in JAVA in programming contest"},"content":{"rendered":"<p>Bignumber problem can be solved easily using BigInteger class in java.Here is a sample for doing this&#8230;.<br \/>\n[code]<br \/>\nimport java.math.BigInteger;<\/p>\n<p>public class BIG<br \/>\n{<br \/>\npublic static void main(String[] args)<br \/>\n{<br \/>\n\/\/initialization<br \/>\nBigInteger N1 = new BigInteger (&quot;1000000000000000000&quot;);<br \/>\nBigInteger N2 = new BigInteger (&quot;123456789123&quot;);<br \/>\nBigInteger N3 = new BigInteger (&quot;50000000000&quot;);<br \/>\n\/\/Math operations<br \/>\nBigInteger mult = N1.multiply(N2); \/\/This is how to send arguments in bigint functions<br \/>\nBigInteger add = N1.add(N2);<br \/>\nBigInteger div= N1.divide(N2);<br \/>\nBigInteger substract1 = N1.subtract(N2); \/\/N1-N2<br \/>\nBigInteger substract2 = N2.subtract(N1); \/\/N2-N1<br \/>\nBigInteger gcd = N1.gcd(N3);<br \/>\n\/\/Printing output<br \/>\nSystem.out.println(&quot;Mult  &quot; + mult);<br \/>\nSystem.out.println(&quot;add  &quot; + add);<br \/>\nSystem.out.println(&quot;div   &quot; + div);<br \/>\nSystem.out.println(&quot;substract1  &quot; + substract1);<br \/>\nSystem.out.println(&quot;substract2 &quot; + substract2);<br \/>\nSystem.out.println(&quot;gcd N1 N3 &quot; + gcd);<br \/>\n}<br \/>\n}<br \/>\n[\/code]<br \/>\nThere are some more built in functions:<\/p>\n<p>BigInteger.ONE; (==1)<br \/>\nBigInteger.ZERO;(==0)<br \/>\nA.abs();<br \/>\nA.add(N);<br \/>\nA.divide(N);<br \/>\nA.divideAndRemainder(N); (returns an array)<br \/>\nA.max(N);<br \/>\nA.min(N);<br \/>\nA.mod(N);<br \/>\nA.multiply(N);<br \/>\nA.remainder(N);<br \/>\nA.signum(N);<\/p>\n<p>A.doubleValue();<br \/>\nA.floatValue();<br \/>\nA.intValue();<br \/>\nA.longValue();<br \/>\nA.toString();<br \/>\nA.compareTo(N)<\/p>\n<p>converting an integer to bigint<br \/>\nBigInteger A = BigInteger.valueOf(20000);<br \/>\nYou can take input using scanner just as you input int,long etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bignumber problem can be solved easily using BigInteger class in java.Here is a sample for doing this&#8230;. [code] import java.math.BigInteger; public class BIG { public static void main(String[] args) { \/\/initialization BigInteger N1 = new BigInteger (&quot;1000000000000000000&quot;); BigInteger N2 = new BigInteger (&quot;123456789123&quot;); BigInteger N3 = new BigInteger (&quot;50000000000&quot;); \/\/Math operations BigInteger mult = N1.multiply(N2); &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.ujjal.net\/?p=7\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Big Number problem in JAVA in programming contest&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-programming-with-java"],"_links":{"self":[{"href":"https:\/\/blog.ujjal.net\/index.php?rest_route=\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ujjal.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ujjal.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ujjal.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ujjal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":0,"href":"https:\/\/blog.ujjal.net\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ujjal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ujjal.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ujjal.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}