Leftmost DigitTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13680 Accepted Submission(s): 5239
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...
3404: [Usaco2009 Open]Cow Digit Game又见数字游戏Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 72 Solved: 48[Submit][Status][Discuss]Description 贝茜和约翰在玩一个数字游戏.贝茜需要你帮助她. 游戏一共进行了G(1≤G≤100)场.第i场游戏开始于一个正整数Ni(l≤Ni≤1,000,000).游戏规则是这样的:双方轮流操作,将当前的数字减去一个数,这个数可以是当前数字的最大数码,也可以是最小的非0数码.比如当前的数是...
P1118 [USACO06FEB]数字三角形Backward Digit Su… 题目描述 FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 <= N <= 10) in a certain order and then sum adjacent numbers to produce a new list with one fewer number. They repeat this until only a single number is left. For example, one instance of the game (when N=4) might go like this: 3 1 2 44 3 67...
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1122题意:给你m个数,选取n个数组成一个整数,使得整数各位的最大数与最小数的差小于2。问有几种选法?解法:DP。dp[i][j]表示以j结尾的i位整数的解法数目。
答案即为sum(dp[n][k] (1<=k<=9,且k在集合S中) )代码:#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include ...
Digit factorialsProblem 34145 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.package mainimport ("fmt""strconv"
)/*
Digit factorialsProblem 34
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Find the sum of all numbers which...
We 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 (using t...
1/**2大意: 求A(n,m)的结果中从左到右第一个非零数3思路: 0是由2*5的得到的,所以将n!中的2,5约掉可得(2的数目比5多,最后再考虑进去即可)4那n!中2 的个数怎么求呢? 5int get2(int n){6 if(n==0)7 return 0;8 return n/2+get2(n/2);9}
10eg: 1*2*3*4*5*6*7*8*9*10 约去2,5可得,,1*1*3*1*1*3*7*1*9*1
11 所以最后肯定是3,7,9.。的数列,,那么在最后的数列中3,7,9,有多少个呢?
12可以这样考...
DescriptionGiven a positive integer N, you should output the most right digit of N^N.
InputThe 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 follow.Each test case contains a single positive integer N(1<=N<=1,000,000,000). OutputFor each test case, you should output the rightmost digit of N^N.
Sample Input ...
P2953 [USACO09OPEN]牛的数字游戏Cow Digit Game题目描述Bessie is playing a number game against Farmer John, and she wants you to help her achieve victory.Game i starts with an integer N_i (1 <= N_i <= 1,000,000). Bessie goes first, and then the two players alternate turns. On each turn, a player can subtract either the largest digit or the smallest non-zero digit from the current number to obtain a ...
1class Solution2{3public:4int count(int n, int x)5 {6int cnt = 0, k;7for (int i = 1; k = n / i; i *= 10)8 {9int high = k / 10;
10if (x == 0)
11 {
12if (high)
13 {
14 high--;
15 }
16else17 {
18break;
19 }
20 }
21 cnt += high * i;
22int c...
题目Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:
Given n = 13,
Return 6, because digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.解题思路题目理解:题目的意思是给定一个数n,计算[0, n]的区间中1出现的次数。具体思路:在面试过程中如果被问到类似的题目,一定不要着急,因为这肯定是一道找规律的题目。最好的办法...
Number of Digit OneGiven an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the following numbers: 1, 10, 11, 12, 13. 数学题,真是为难了数学拙计的我了。递归分治,拿8192举栗子:把8192拆成:1-999 -> 递归(999)1000-1999 -> 1000个1 + 递归(999)2001-2999 -> 递归(999)..8000-8192 ->...
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.Hint:1. Beware of overflow.解题思路:看得答案。很烧脑,没有看得很明白。这题实际上相当于一道找规律的题。那么为了找出规律,我们就先来列举下所有含1的数字,并每10个统计下个数,如下所示...
题目链接:http://acm.tju.edu.cn/toj/showp2502.html2502. Digit GeneratorTime Limit: 1.0 Seconds Memory Limit: 65536KTotal Runs: 2426 Accepted Runs: 1579For a positive integer N, the digit-sum of N is defined as the sum of N itself and its digits. When M is the digitsum of N, we call N a generator of M.
For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore, 245 is a generator...
解决本题使用数学中的快速幂取余:该方法总结挺好的:具体参考http://www.cnblogs.com/PegasusWang/archive/2013/03/13/2958150.html #include<iostream>
#include<cmath>
usingnamespace std;
int PowerMod(__int64 a,__int64 b,int c)//快速幂取余 {int ans=1;a=a%c;while(b>0){if(b%2==1)//如果为奇数时,要多求一步,可以提前放到ans中 ans=(ans*a)%c;b=b/2;//不断迭代 a=(a*a)%c;//把(a^2)%c看成一个整体 }return ans;
}
i...