Blue Bridge Cup algorithm training ALGO-149 5-2 Evaluation Index

Source: Internet
Author: User

Algorithm training 5-2 seeking exponential time limit: 1.0s memory Limit: 256.0MB problem description known N and m, print n^1,n^2,...,n^m. Required to be implemented with static variables. N^m represents the M-th side of N. Known N and m, print n^1,n^2,...,n^m. Required to be implemented with static variables. N^m represents the M-th side of N. (Each line shows 5 numbers, each with a width of 12, right-justified) the sample enters a sample input that satisfies the problem.
Cases:
3 8 Sample output corresponds to the output of the sample input above.
Cases:
Data size and convention the range of each number in the input data.
Example: N^m is less than the representation range of Int. Topic Analysis: This is a subject of violent cracking. You need to have a record of N's M-time num, make num = 1, then loop m times, give Num multiply n each time, and then use the printf formatted output. you should avoid using (int) Math.pow (n, i) every time i + one loop to calculate the M-time of N, as this will result in a m-1 repeat calculation. When we calculate the 3 times of N, the 2 times of N has been calculated, so setting a record number will make the program more efficient to execute. Example code:
1 ImportJava.util.Scanner;2 3  Public classMain {4      Public Static voidMain (string[] args) {5Scanner sc =NewScanner (system.in);6         intn =sc.nextint ();7         intm =sc.nextint ();8         intnum = 1;//Record n's i-th square9          for(inti = 1; I <= m; i++){TenNum *=N; OneSystem.out.printf ("%12d", num); A             if(i% 5 = = 0){ -System.out.print ("\ n"); -             } the         } -     } -}

Blue Bridge Cup algorithm training ALGO-149 5-2 Evaluation Index

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.