Kattis之旅——Inverse Factorial


题目意思就是已知n的阶乘,求n。
当输入的阶乘小于10位数的时候,我们可以用long long将字符串转化成数字,直接计算。
而当输入的阶乘很大的时候,我们就可以利用位数去大概的估计n。
//Asimple
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, num, res, ans, len;string str;
void input() {
cin >> str;
len = str.size();
if( len < ) {
ll i = ;
ll ans = ;
while( true ) {
ans *= i;
if( ans == atoi(str.c_str()) ) {
cout << i;
break;
}
i ++;
}
} else {
ll i = ;
double ans = ;
while( true ) {
ans += log10(i);
if( floor(ans)==len ) {
cout << i;
break;
}
i ++;
}
}
} int main(){
input();
return ;
}
Kattis之旅——Inverse Factorial的更多相关文章
- Kattis之旅——Factovisors
The factorial function, n! is defined thus for n a non-negative integer: 0! = 1 n! = n * (n-1)! (n & ...
- Kattis之旅——Prime Reduction
A prime number p≥2 is an integer which is evenly divisible by only two integers: 1 and p. A composit ...
- Kattis之旅——Chinese Remainder
Input The first line of input consists of an integers T where 1≤T≤1000, the number of test cases. Th ...
- Kattis之旅——Fractional Lotion
Freddy practices various kinds of alternative medicine, such as homeopathy. This practice is based o ...
- Kattis之旅——Rational Arithmetic
Input The first line of input contains one integer, giving the number of operations to perform. Then ...
- Kattis之旅——Number Sets
You start with a sequence of consecutive integers. You want to group them into sets. You are given t ...
- Kattis之旅——Divisible Subsequences
Given a sequence of positive integers, count all contiguous subsequences (sometimes called substring ...
- Kattis之旅——Prime Path
The ministers of the cabinet were quite upset by the message from the Chief of Security stating that ...
- Kattis之旅——Perfect Pth Powers
We say that x is a perfect square if, for some integer b, x = b2. Similarly, x is a perfect cube if, ...
随机推荐
- Node.js之npm使用
1.使用国内镜像 本人window8系统安装node.js之后,使用npm的命令安装Express一直失败: npm install express -g (以上命令会将 Express 框架安装在当 ...
- python变量交换及注释种类,注释注意事项/注释排查方法
#小练习作业 # texe1 = '能提笔安天下' # print(texe1) # string1 = '武能上' # string2 = '定乾坤' # print(string1,string2 ...
- 158A
#include <iostream> #include <algorithm> using namespace std; int main() { int groups[10 ...
- syslog-ng 学习
摘要:http://luyongxin88.blog.163.com/blog/static/925580720112275183903/ 因为工作的需要,涉及到了syslog-ng.现在看来,在外包 ...
- js, css混淆
原理:调用yuicompressor-2.4.8.jar, 生成混淆后的文件,强大的它能处理css,js. 1,准备一个txt,列出所需要合并的js,如js.txt jquery-1.9.1.min. ...
- vbox中安装mac系统
参考: https://www.cnblogs.com/liming2017/p/7566953.html
- APP网络优化篇
Android Addresses are cached for 600 seconds (10 minutes) by default. Failed lookups are cached for ...
- vim 常用
Format JSON :%!python -m json.tool 1. define custom function and use it define function in .vimrc fu ...
- linux统计文件夹大小
统计总大小: du -sh dirname 统计文件夹内部各文件大小及总大小: du -h dirname
- iOS 开发笔记-控制器tab切换view显示
在开发过程中,我们常常会碰到一种情况就是,在一个controller里面,经常要放很多复杂的控制,最常用的就是tar切换.tar切换,原理就是在一个controller里面,显示另一个controll ...