【水整数幂】#30 A. Accounting
来源:互联网 发布:淘宝上浴沙多少钱 编辑:程序博客网 时间:2024/04/30 00:25
因为数值范围太小甚至都觉得用快速幂是不是大材小用了……
注意幂运算的速度,以及正负符号的判断,特判成立时记得return免得多重输出,基本上算法难度没有,作为一道骗WA的水题还是不错的= =。
#include <cmath> #include <vector> #include <cctype> #include <cstdio> #include <string> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std;int Pow(int a,int k){ int sum=1; while(k){ if(k&1)sum=sum*a; a=a*a; k>>=1; //k=k>>1; } return sum; } int main(){int a,b,n;scanf("%d%d%d",&a,&b,&n);if(a==0&&b!=0){puts("No solution");return 0;}else if(b==0){printf(a==0?"1":"0");return 0;}else {int Mi=b/a;if(abs(Mi)==1){if(Mi==1)printf("1");else printf(n%2==0?"No solution":"-1");return 0;}else for(int i=1;Pow(i,n)<=abs(Mi);i++){if(Pow(i,n)==Mi){printf("%d",i);return 0;}else if(Pow(0-i,n)==Mi){printf("-%d",i);return 0;}}printf("No solution");}return 0;}
0 0
- 【水整数幂】#30 A. Accounting
- A. Accounting
- accounting
- NEUQ 1420: Problem A - Y2K Accounting Bug
- POJ 2459 Feed Accounting 水题一道
- POJ 2459 Feed Accounting(水~)
- a+b(整数)
- 问题 A: 整数连接
- 大整数 a-b
- 1000: 整数a+b
- HDU1002: A + B Problem II (很水的大整数)
- 将整数A转换为整数B
- 181- 整数A转化为整数B
- PeachTree Accounting
- Accounting Document
- RADIUS Accounting
- FacePalm Accounting
- accounting assistant
- 黑马程序员_C#生成验证码图片
- 解决zsh中无法正常使用home和end等键的问题
- Action包和命名空间及其动态方法调用
- 鸟哥私房菜 第6章 Linux的文件权限与目录配置 课后习题
- 性能测试之稳定性测试
- 【水整数幂】#30 A. Accounting
- UVa 872 - Ordering 输出全拓扑排序
- ElasticSearch入门笔记
- 菜鸟对于hash思想的总结
- [文献阅读之]Unbiased Look at Dataset Bias(2011CVPR)关于数据集偏见的讨论
- nginx 运行于RT5350
- leetcode: Word Search
- 性能测试之开源的性能测试工具
- Spring源码学习IOC(1):Resource的分析