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, ...
随机推荐
- dll相关总结
1.动态链接库的使用有两种方式,一种是显式调用.一种是隐式调用. (1) 显式调用:使用LoadLibrary载入动态链接库.使用GetProcAddress获取某函数地址. (2) 隐式调用:可以使 ...
- [py]字符串转换为列表
字符串转换为列表 "[1,2,3]" ==> [1,2,3]
- (转)MySQL排序原理与案例分析
前言 排序是数据库中的一个基本功能,MySQL也不例外.用户通过Order by语句即能达到将指定的结果集排序的目的,其实不仅仅是Order by语句,Group by语句,Distinct ...
- 利用TensorFlow实现多元逻辑回归
利用TensorFlow实现多元逻辑回归,代码如下: import tensorflow as tf import numpy as np from sklearn.linear_model impo ...
- 大数据工具比较:R 语言和 Spark 谁更胜一筹?
本文有两重目的,一是在性能方面快速对比下R语言和Spark,二是想向大家介绍下Spark的机器学习库 背景介绍 由于R语言本身是单线程的,所以可能从性能方面对比Spark和R并不是很明智的做法.即使这 ...
- docker每次都重新拉取远程镜像的问题
将镜像上传到远程之后,dockerfile按理来说只需一次拉取远程镜像就好了,之后每次都是使用第一次拉取的远程镜像. 但是实际上出现的问题是:dockerfile每次都从远程拉取镜像,浪费了资源和时间 ...
- Web API 入门 一
因为只是是一个简单的入门.所有暂时不去研究web API一些规范.比如RESTful API 这里有个接收RESTful API的.RESTful API 什么是WebApi 看这里:http://w ...
- 树结构控件实例 TreeControl
树结构控件实例 书:157 <?xml version="1.0" encoding="utf-8"?> <s:Application xml ...
- JAVA8流操作
* Stream 的三个操作步骤: * 1创建Stream * 2中间操作 * 3终止操作 package airycode_java8.nice6; import airycode_java8.ni ...
- 将n的k位s置1
实例四:将n的k位s置1 方法:result =n|(1<<k) 只使k位变为1,其他位为0,再进行或操作,1与任何数的或操作都是1. 解释: 原数 0000 1011 ---11 数值1 ...