题意
给你n,让你输出n位数中平方后尾数是987654321的数的个数。
思路
一个数,只考虑最后i位,那么这个数平方之后的最后i位和这个数的最后i位平方后的最后i位相同,所以我们只要考虑1~9位数中谁的平方最后9位是987654321就可以了,本地打个表,发现只有8个数符合要求,接下来,对于10位数,我们就有98=72种组合对于11位数就是908=720种组合,这样我们就发现了,超过10位数的话,就在73后面补上n-10个零就行了,这样大数时也搞定了。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <iostream> #include <algorithm> #include <queue> #include <vector> #include <cstdlib> #include <cstdio> #include <string> #include <cstring> #include <ctime> #include <iomanip> #include <cmath> #include <set> #include <stack> #include <cmath> using namespace std; int main(){ int a = 0; scanf("%d",&a); if (a <= 8) { printf("0n"); }else if(a == 9){ printf("8n"); }else{ printf("72"); for (int i = 10; i < a; i++) { printf("0"); } printf("n"); } return 0; } |