HDU 6182A Math Problem(快速幂)

来源:互联网 发布:js修改confirm的是否 编辑:程序博客网 时间:2024/06/10 07:08

A Math Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1632    Accepted Submission(s): 580


Problem Description
You are given a positive integer n, please count how many positive integers k satisfy kkn.
 

Input
There are no more than 50 test cases.

Each case only contains a positivse integer n in a line.

1n1018
 

Output
For each test case, output an integer indicates the number of positive integers k satisfy kkn in a line.
 

Sample Input
14
 

Sample Output
12
 

Source
2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
想法:快速幂+暴力过
代码:
#include<stdio.h>#include<string.h>#include<math.h>typedef long long LL;LL pow(LL a,int b){    LL ans=1,base=a;    while (b>0)    {        if (b%2==1)            ans=base*ans;        base=base*base;        b/=2;    }    return ans;}int main(){    long long n;    while(scanf("%lld",&n)!=EOF)    {       long long i,k;       for(i=15;i>=1;i--)       {           if(pow(i,i)<=n)           {               k=i;               break;           }       }       printf("%lld\n",k);    }    return 0;}



原创粉丝点击