HDU 1061 rightmost digit problem solving method

Source: Internet
Author: User

Find the rightmost number of the value of a large number of n^n, that is, the lowest bit.

It will be able to solve a simple dichotomy.

Just pay attention to overflow, just put n% 10 after. I will not overflow, instead of using a long long.


#include <stdio.h>int rightmost (int n, int n) {if (n = = 0) return 1;int t = rightmost (N/2, n); t = T * t% 10;; if (n% 2) t *= n;return t% 10;} int main () {int T, n;scanf ("%d", &t), while (t--) {scanf ("%d", &n);p rintf ("%d\n", rightmost (n, n%10));} return 0;}



Copyright notice: The author Jing Heart, Jing Space address: http://blog.csdn.net/kenden23/. Reproduced only by the author's consent.

HDU 1061 rightmost digit problem solving method

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.