The Cat in the Hat POJ - 1289
题意:给你来两个数A,B 。其中A=(n+1)k, B=nk 输出:(nk-1)/(n-1) 和 ∏ (n+1)k-i ni
思路:关键就是怎么求n和k。本来想这n一定是几个质因数的乘积,那么k一定是其中最小的(B=a1k1 a2 k2 a3 k3....an kn)。
好了,但是咱有更加简单的办法,那就是利用pow()函数来开k次方!!帅不帅气!
#include<iostream>
#include<cmath>
using namespace std; int POW(int x, int n)
{
int ans = ;
for (; n;n>>=, x*=x)
if (n & )ans *= x;
return ans;
} int main()
{
int A, B;
while (cin >> A >> B, A || B)
{
int n, k;
if (B <= )printf("0 %d\n", A);
else
{
for (int i = ; i <= ; ++i)
{
double h1 = pow(A, 1.0 / i*1.0) - ;
double h2 = pow(B, 1.0 / i*1.0);
if (abs(h1 - h2) < 1e-)
{
n = h1 + 0.5;
k = i;
break;
}
}
int ans1 = POW(n, k) / (n - );
int ans2=;
for (int i = ; i <= k; ++i)
{
ans2 += POW(n + , k - i)*POW(n, i);
}
printf("%d %d\n", ans1, ans2);
}
}
}
The Cat in the Hat POJ - 1289的更多相关文章
- uva 107 - The Cat in the Hat
The Cat in the Hat Background (An homage to Theodore Seuss Geisel) The Cat in the Hat is a nasty c ...
- UVa 107 - The Cat in the Hat (找规律,注意精度)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- 杂题 UVAoj 107 The Cat in the Hat
The Cat in the Hat Background (An homage to Theodore Seuss Geisel) The Cat in the Hat is a nasty c ...
- [POJ 1521]--Entropy(哈夫曼树)
题目链接:http://poj.org/problem?id=1521 Entropy Time Limit: 1000MS Memory Limit: 10000K Description A ...
- 更换Red Hat Enterprise Linux 7 64位的yum为centos的版本
查看redhat原有的yum包有哪些: [root@localhost ~]# rpm -qa|grep yum yum-utils-1.1.31-24.el7.noarch yum-langpack ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- [SinGuLaRiTy] 数论题目复习
[SinGuLaRiTy-1020] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [CQBZOJ 1464] Hankson 题目描述 H ...
- 五、Pandas玩转数据
Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...
- 【Python五篇慢慢弹(5)】类的继承案例解析,python相关知识延伸
类的继承案例解析,python相关知识延伸 作者:白宁超 2016年10月10日22:36:57 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给 ...
随机推荐
- 判断使用设备是PC还是phone
<script type="text/javascript"> //如果是手机设备,则.. if(/Android|webOS|iPhone|iPod|BlackBer ...
- Umbraco 7 特点
Umbraco 7 features at a glance The backend is mainly built on .NET C# MVC. There are some leftovers ...
- HTTP 错误 500 调用loadlibraryex失败
HTTP 错误 500.0 - Internal Server Error 调用 LoadLibraryEx 失败,在 ISAPI 筛选器 C:\Windows\Microsoft.NET\Frame ...
- Hash Table (youtube)
here is a link for youtube about hash table which is super good https://www.youtube.com/watch?v=h2d9 ...
- html页面边框的另一种写法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Python 练习:三级菜单选择城市
info = { 'GuangDong':{ 'GuangZhou': ['TianHe', 'HaiZhu'], 'MaoMing': ['MaoNan', 'DianBai']}, 'ShanDo ...
- [转]Serif和Sans-serif字体的区别
在西方国家罗马字母阵营中,字体分为两大种类:Sans Serif和Serif,打字机体虽然也属于Sans Serif,但由于是等宽字体,所以另外独立出Monospace这一种类,例如在Web中,表示代 ...
- 2018-01-17 Antlr4实现简单语言之整数比较表达式
续上文Antlr4: 修改语法规则更接近普通BNF格式. 例程 为先=1 为先 为2 => 返回false '为'作为关键词, 与数字可以连写, 但必须与变量名用空格间隔: 变量一=1 变量二= ...
- css清除默认样式
CSS 清除默认样式 通常有以下几句就够了: *{margin:0;padding:0} li{list-style:none} img{vertical-align:top;border:non ...
- python自动化开发-9 进程 线程
进程与线程 程序并不能单独运行,只有将程序装载到内存中,系统为它分配资源才能运行,而这种执行的程序就称之为进程.线程是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一 ...