A+A的每一位的数字的和=B问你每一个B对应 的最小的A 是多少不然输出0; 1 #include <cstdio>2 #include <iostream>3 #include <cstring>4usingnamespace std;5constint N=100005;6int ans[2*N],tmp,cnt,n,t;7void fuc(){8 memset(ans,0,sizeof(ans));9for(int i=1;i<=N;i++){
10 tmp=i; cnt=0;
11while(tmp>0){
12 cnt+=tmp%10;
13 tmp/=10;
14 }
15 cnt+=i;
16if(ans[cnt]==0...
题目链接: 1061 ( Rightmost Digit )/*** hdu1061 Rightmost Digit(快速幂取模)**/#include <iostream>
using namespace std;typedef long long LL;LL fastPow(LL a, LL b, LL mod = LLONG_MAX)
{a %= mod;LL t = 1;while (b) {if (b&1) t = t*a%mod;a = a*a%mod;b >>= 1;}return t%mod;
}int main()
{int T;cin >> T;while (T--) {int n;cin >> n;cout << fastPow(n, n, 10) << endl;}return 0;
}原文:https://www.cnblogs.com/z...
Leftmost DigitTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13574 Accepted Submission(s): 5216
Problem Description
Given a positive integer N, you should output the leftmost digit of N^N.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follo...
我还想把它当成一道数学题做,但是发现代码实现太繁琐。直接搜索肯定会超时的,所以我要确定遍历的区间。区间的上界我找到了,但是我无法准确的确定区间下界。所以我觉得这个方法不靠谱,就看了题解。题解用的预处理,先把所有十万以内的正整数都遍历一遍,得到离i最近的以i为最小生成元的数t。以t为下标,将i赋值给ans[t],继续遍历。如果接下来存在另一个i,为t的生成元,并且比原先的ans[t]更小,就ans[t]=i,否则不处理。最后直...
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn?1 + Fn?2, where F1 = 1 and F2 = 1.Hence the first 12 terms will be:
F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 144The 12th term, F12, is the first term to contain three digits.What is the index of the first term in the Fibonacci sequence to contain 1000 digits?找到第一个1000位的斐波...
暴力DFS+验证。验证如果是o(n)检验可能复杂度会太高,事实上可以o(1)进行,这个可以o(n*n)dp预处理。#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
usingnamespace std;constint maxn=20;
bool flag[maxn];
bool r;
int a[maxn];
int n,sum;int mul[15][15];bool check(int s)
{if(s==sum) return1;return0;
}void dfs(int deep,int tot)
{if(deep==n-1){if(check(tot)){r=1;for(int i=0;i<=deep;i++){...
数学题。弄懂了之久其实就是解一个一元二次方程 x*(x-1)/2=y 。如果y==0了。表明刚好是这个数。不是的话,就x取大一位然后 y-n 再%9 。不过记得 %9==0的时候是9。不会出现0。#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-6
#define LL long ...
找规律!求N!最后非0位的值。比方2是120的最后一个不是0的值。
输入N比較大,要大数保存。
注意到最后0的个数是与5的因数的个数相等。设f(n)为n!的最后非0位。
那么f(n)=((n%5)!* f(n/5) *2^(n/5))%10
因数2的个数始终大于5,从1開始每连续5个划分为1组,当中5的倍数仅仅提取出一个因数5后,
组成一个新的数列1到n/5,我们有1*2*3*4*5=6*7*8*9*5=2(取最后一个非0位),这里就是2^(n/5)。
再乘上剩下来的几个数字就可以
(比...
来源:http://m.blog.csdn.net/article/details?id=70861055Trung is bored with his mathematicshomeworks. He takes a piece of chalk and starts writing a sequence ofconsecutive integers starting with 1 to N (1 < N < 10000). After that, hecounts the number of times each digit (0 to 9) appears in the sequence. Forexample, with N = 13, the sequence is: 12345678910111213In this sequence, 0appears once, 1 a...
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.Find the sum of all numbers which are equal to the sum of the factorial of their digits.
Note: as 1! = 1 and 2! = 2 are not sums they are not included.#include <iostream>
#include <vector>
using namespace std;vector<int> int_vet(int a)
{vector<int> res;while (a){int tmp = a % 10;a /= 10;res.push_back(tmp);}return res;
}int a[10] = { 0 }...
题目链接我的思路略复杂,这里介绍一个比较简洁的做法。对于 $b \le \sqrt{N}$,暴力枚举 $b$。对于 $b > \sqrt{N}$, 注意到在 $b$ 进制下 $N$ 至多有 2 个数位,且最高位的取值小于 $\sqrt{N}$,此时可以暴力枚举最高位上的数字。扩展若数据范围扩大到 $10^{18}$ 该怎么做?原文:https://www.cnblogs.com/Patt/p/11902128.html
descptionWe have a sorted set of digits D, a non-empty subset of {‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘}. (Note that ‘0‘ is not included.)Now, we write numbers using these digits, using each digit as many times as we want. For example, if D = {‘1‘,‘3‘,‘5‘}, we may write numbers such as ‘13‘, ‘551‘, ‘1351315‘.Return the number of positive integers that can be written...
#include<cstdio>
#include<cstring>int num[3],tot,n,f;
char s[3][100],ans[3][100];int check()
{char str[100];int a=0,b=0,c;for(int i=0;i<num[0];i++)a=a*10+s[0][i]-'0';for(int i=0;i<num[1];i++)b=b*10+s[1][i]-'0';c=a*b;for(int i=num[2]-1;i>=0;i--){str[i]='0'+c%10;c/=10;}if(c>0||str[0]=='0')return 0;for(int i=0;i<num[2];i++)if(s[2][i]!=str[i]&&s[2][i]!='*')return 0;return 1;
}void dfs(int a,int b)
{if...
题目链接:huangjing思路:这个题目想到dfs很容易,但是纠结在这么像杨辉三角一样计算那些值,这个我看的队友的,简直厉害,用递归计算出杨辉三角顶端的值。。。。具体实现详见代码。。。题目:Language:
Default
Backward Digit SumsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4285 Accepted: 2474Description
FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <...
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9518 Accepted Submission(s): 2758Problem Description假设:
S1 = 1
S2 = 12
S3 = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11 = 12345678912
............
S18 = 123456789123456789
..................
现在我们把所有的串连接起来
S = 1121231234.......123456789123456789112345678912........