Java Data Structure after-school exercises-what is the power of 2 (mod5?

Source: Internet
Author: User
Package algorithm; public class algorithm_modtest {public static void main (string [] ARGs) {modprocess MP = new modprocess (2,100, 5); MP. findmodprocess (); MP. getresult () ;}} class modprocess {int basenumber; int exponent; int modnumber; int minexponent; int modresult; modprocess (int B, int e, int m) {This. basenumber = B; this. exponent = E; this. modnumber = m; this. minexponent = 1; this. modresult = 0;} public void findmodprocess () {If (this. exponent <this. modnumber) {This. modresult = getexponentvalue (this. basenumber, this. exponent) % This. modnumber;} else {This. minexponent = findminexponent (); // find the smallest index int remainexponent = This. exponent; while (remainexponent> = This. minexponent) {remainexponent = remainexponent-this. minexponent;} int remainnumber = getexponentvalue (this. basenumber, remainexponent); this. modresult = remainnumber % This. modnumber ;}} public int findminexponent () // find the smallest index {Boolean B = true; int sum = This. basenumber; int mincount = 1; while (B) {If (Sum-1) % (this. modnumber) = 0) {B = false;} else {sum = sum * This. basenumber; mincount ++;} return mincount;} public void getresult () // result processing {system. out. println ("modresult:" + this. modresult);} public int getexponentvalue (INT base, int e) // obtain the integer index value {int result = 1; for (INT I = 0; I <E; I ++) {result = Result * base;} return result ;}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.