Codeforces 630L-L. Cracking the Code【整数快速幂】

青旅半醒 2022-08-21 12:56 225阅读 0赞

L. Cracking the Code

time limit per test

0.5 seconds

memory limit per test

64 megabytes

input

standard input

output

standard output

The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.

A young hacker Vasya disassembled the program and found the algorithm that transforms the shown number into the activation code.Note: it is clear that Vasya is a law-abiding hacker, and made it for a noble purpose — to show the developer the imperfection of their protection.

The found algorithm looks the following way. At first the digits of the number are shuffled in the following order . For example the shuffle of 12345 should lead to 13542. On the second stage the number is raised to the fifth power. The result of the shuffle and exponentiation of the number 12345 is 455 422 043 125 550 171 232. The answer is the 5 last digits of this result. For the number 12345 the answer should be 71232.

Vasya is going to write a keygen program implementing this algorithm. Can you do the same?

Input

The only line of the input contains a positive integer five digit number for which the activation code should be found.

Output

Output exactly 5 digits without spaces between them — the found activation code of the program.

Examples

input

  1. 12345

output

  1. 71232

解题思路:

将输入的n(abcde)转化成acedb后,取五次幂后五位。数据坑10000,结果是00000.

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. using namespace std;
  5. long long mod(int a,int b,int m)
  6. {
  7. long long ans=1,i;
  8. for(i=1;i<=b;i++)
  9. {
  10. ans=ans*a%m;
  11. }
  12. return ans;
  13. }
  14. int main()
  15. {
  16. int a,b,c,d,e;
  17. scanf("%1d%1d%1d%1d%1d",&a,&b,&c,&d,&e);
  18. int num=a*10000+c*1000+e*100+d*10+b;
  19. int wc=(int)mod(num,5,100000);
  20. //printf("%d\n",wc);
  21. int aa,bb,cc,dd,ee;
  22. aa=bb=cc=dd=ee=0;
  23. aa=wc/10000;
  24. wc=wc%10000;
  25. bb=wc/1000;
  26. wc=wc%1000;
  27. cc=wc/100;
  28. wc=wc%100;
  29. dd=wc/10;
  30. wc=wc%10;
  31. ee=wc;
  32. printf("%d%d%d%d%d",aa,bb,cc,dd,ee);
  33. return 0;
  34. }

发表评论

表情:
评论列表 (有 0 条评论,225人围观)

还没有评论,来说两句吧...

相关阅读

    相关 矩阵/整数快速/乘

    参考来源: [整数快速乘法,整数快速幂,矩阵快速幂【参考博客】][Link 1] [参考题目 poj 3070][poj 3070] 先说明一下基本的数学常识: >