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, ...
随机推荐
- 266A
#include <iostream> #include <string> using namespace std; int main() { string stones; i ...
- LVS+Keepalived高可用部署
一.LVS+Keepalived高可用部署 一.keepalived节点部署 1.安装keepalived yum install keepalived ipvsadm -y mkdir -p /op ...
- configure.in详解
configure.in文件里基本的内容就是一系列的m4宏,在运行时根据传递给它们的参数,定义的宏就会扩展为shell的脚本代码段.也可以手工书写shell代码.不过我们就不说这个了,要想完全的理解c ...
- dfs1321
比较抽象吧,看到题时一点思想也没有,参考了别人的代码才知道...渣渣 #include <iostream>#include <stdio.h>#include <str ...
- JS通过类名判断是否都必填
//判断class='required' 是否都必填 function required() { var flag = true; $(".required").each(func ...
- Elasticsearch集群管理工具head插件安装
Elasticsearch-head是一个elasticsearch的集群管理工具,它是完全由html5编写的独立网页程序,你可以通过插件把它集成到es.或直接下载源码,在本地打开index.html ...
- Dart server side call dll
今天,查看文档时发现Dart运行在服务端下可以调用本地实现(C/C++ dll). 我想应该有大用处 拿出来分享! 一 先做Dart库 //sse.dart library sample_synchr ...
- 使用sqlite3解决IDEA中SVN更新提示cleanup却无法cleanup的问题
用idea开发项目,更新svn有时莫名其妙的出现 Error:Error performing cleanup for 'D:\SourceProject\XXXX': svn: E155004: T ...
- !! MACD战法总结
我现在只发技术,不预测大盘.其实说实话,大盘不用预测,只要按照guoweijohn战法,有买入信号就入,有卖出信号就出..你也会成为股神..不是吹牛,且听慢慢分解 股市有三种市场: 一.牛市 二.震荡 ...
- 字符串转化为int数组
String a = "1,2,3,4,5,6" String str[] = a.split(","); int array[] = new int[str. ...