码迷,mamicode.com
首页 > 其他好文 > 详细

玲珑杯 Round 19 A simple math problem

时间:2017-07-30 15:45:18      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:str   desc   can   frame   memory   ace   alt   sequence   i++   

Time Limit:2s Memory Limit:128MByte

Submissions:1599Solved:270

DESCRIPTION

You have a sequence anan, which satisfies:

技术分享

Now you should find the value of ?10an??10an?.

INPUT
The input includes multiple test cases. The number of test case is less than 1000. Each test case contains only one integer n(1n109)n(1≤n≤109)。
OUTPUT
For each test case, print a line of one number which means the answer.
SAMPLE INPUT
5
20
1314
SAMPLE OUTPUT
5
21
1317
官方题解
技术分享
#include <iostream> 
#include <algorithm> 
#include <cstring> 
#include <cstdio>
#include <vector> 
#include <queue> 
#include <cstdlib> 
#include <iomanip>
#include <cmath> 
#include <ctime> 
#include <map> 
#include <set> 
using namespace std; 
#define lowbit(x) (x&(-x)) 
#define max(x,y) (x>y?x:y) 
#define min(x,y) (x<y?x:y) 
#define MAX 100000000000000000 
#define MOD 1000000007
#define pi acos(-1.0) 
#define ei exp(1) 
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f 
#define mem(a) (memset(a,0,sizeof(a))) 
typedef long long ll; 
ll n,i;
ll quick_pow(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=ans*a;
        b>>=1;
        a*=a;
    }
    return ans;
}
int main()
{
    while(scanf("%lld",&n)!=EOF)
    {
        if(n<=10) {printf("%lld\n",n);continue;}
        for(i=0;i<=11;i++)
        {
            if(quick_pow(10,i)-i+2<=n && quick_pow(10,i+1)-i>=n)
            {
                printf("%lld\n",n+i);
                break;
            }
        }
    }
    return 0;
}

 

玲珑杯 Round 19 A simple math problem

标签:str   desc   can   frame   memory   ace   alt   sequence   i++   

原文地址:http://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7259199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!