Kattis之旅——Fractional Lotion
Freddy practices various kinds of alternative medicine, such as homeopathy. This practice is based on the belief that successively diluting some substances in water or alcohol while shaking them thoroughly produces remedies for many diseases.
This year, Freddy’s vegetables appear to have caught some disease and he decided to experiment a little bit and investigate whether homeopathy works for vegetables too. As Freddy is also a big fan of mathematics, he does not strictly insist that the substances have small concentrations, but he instead requires the concentrations to be reciprocals of integers (1/n). In experiments, some of the vegetables really got much better.
Seeing Freddy’s successes, a fellow gardener also wants to try one of these potions and asks for a flask. Freddy has one flask of the potion in concentration 1/n and does not want to give it all out. Your task is to find out in how many ways the potion can be split into two flasks and diluted so that the resulting potions both have the same volume as the original one and the resulting concentrations also are reciprocals of integers — we do not want to end up with useless fluid, do we?
Input
Each line of the input describes one test case. The line contains the expression “1/n” representing the original concentration. You are guaranteed that 1≤n≤10000. There are no spaces on the line.
Output
For each test case, output a single line with the total number of distinct pairs {x,y}
of positive integers satisfying 1/x+1/y=1/n. Pairs differing only in the order of the two numbers are not considered different.
Sample Input 1 | Sample Output 1 |
---|---|
1/2 |
2 |
感谢大佬的思路:http://blog.csdn.net/HelloWorld10086/article/details/44022071?locationNum=8&fps=1
//Asimple
#include <bits/stdc++.h>
#define CLS(a, v) memset(a, v, sizeof(a))
using namespace std;
typedef long long ll;
const int maxn = 10000+5;
ll n, m, s, res, ans, len, T, k, num;
int pr[maxn];
char str[maxn];
int a[maxn] = {0}; void get_pr(){
len = 0;
for(int i=2; i<maxn; i++) {
if( a[i]==0 ) {
pr[len++] = i;
int j = i;
while( j < maxn ) {
a[j] = 1;
j += i;
}
}
}
} void input() {
get_pr();
while( cin >> str ){
n = atoi(str+2);
res = 0;
CLS(a, 0);
for(int i=0; i<len && n>1; i++) {
if( n%pr[i]==0 ) {
while( n%pr[i]==0 ) {
a[res]++;
n /= pr[i];
}
res ++;
}
}
ans = 1;
for(int i=0; i<res; i++) {
ans *= (a[i]*2+1);
}
cout << (ans+1)/2 << endl;
}
} int main(){
input();
return 0;
}
数论菜鸟瑟瑟发抖。
Kattis之旅——Fractional Lotion的更多相关文章
- 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之旅——Factovisors
The factorial function, n! is defined thus for n a non-negative integer: 0! = 1 n! = n * (n-1)! (n & ...
- 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之旅——Inverse Factorial
题目意思就是已知n的阶乘,求n. 当输入的阶乘小于10位数的时候,我们可以用long long将字符串转化成数字,直接计算. 而当输入的阶乘很大的时候,我们就可以利用位数去大概的估计n. //Asim ...
- 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, ...
随机推荐
- LINUX的DNS怎么设置?linux下如何修改DNS地址
LINUX的DNS怎么设置?linux下如何修改DNS地址 https://jingyan.baidu.com/article/870c6fc32c028eb03fe4be30.html Linux下 ...
- iOS 正则表达式(二) RegexKitLite使用
下面介绍的是iOS的一个第三方库,RegexKitLite .使用起来是非常方便的,不过是2008年写的,MAC模式,我们在使用的时候,需要作两步操作. RegexKitLite 导入 我们在gith ...
- python模拟艺龙网登录requests包
对比urllib.urllib2与requests不难发现,前者功能更强大,但是实现一个功能要写很多的代码,后者,requests代码简洁,用起来更快速 下面一个模拟登录的代码:看看吧一共也没有几行就 ...
- 关于Stuck Archiver的疑问
客户使用crsctl stat res -t命令去查看RAC集群状态时,发现异常,知晓Stuck Archiver代表归档满,问我们为什么RAC是同一个库,只有实例1显示Stuck Archiver, ...
- UML学习笔记(五)--顺序图
顺序图是用来描述对象自身及对象间信息传递顺序的视图.它用来表示用例中的行为顺序.当执行一个用例行为时,顺序图中的每条消息对应了一个类操作或状态机中引起转换的触发事件.它着重显示了参与相互作用的对象和所 ...
- Nginx配置文件具体配置解释
Nginx配置文件具体配置解释 #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错 ...
- 解析img图片没找到onerror事件
本篇文章主要介绍了img图片没找到onerror事件 Stack overflow at line: 0 需要的朋友可以过来参考下,希望对大家有所帮助 打开网页时提示 Stack overflow a ...
- Git branch 分支与合并分支
Git branch 分支 查看当前有哪些branch bixiaopeng@bixiaopengtekiMacBook-Pro xmrobotium$ git branch * master 新建一 ...
- PB中datewindow单双行显示不同颜色
调出datewindow,找到detail中的列,右击properties,左侧Background中的color属性添加 IF(MOD(GETROW(),2)=0,RGB( 255, 250, 20 ...
- wxpython(python3.5)安装
安装步骤: http://blog.csdn.net/xiaodong193/article/details/51920283 注意:安装软件前需要阅读其中的README.txt,可快速知道安装方法, ...