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, ...
随机推荐
- 从Trie树(字典树)谈到后缀树
转:http://blog.csdn.net/v_july_v/article/details/6897097 引言 常关注本blog的读者朋友想必看过此篇文章:从B树.B+树.B*树谈到R 树,这次 ...
- POJ1611:The Suspects(模板题)
http://poj.org/problem?id=1611 Description Severe acute respiratory syndrome (SARS), an atypical pne ...
- BI-LSTM and CRF using Keras
问题1:CUDA_ERROR_OUT_OF_MEMORY: How to activate multiple GPUs from Keras in Tensorflow import keras.ba ...
- .Net Core:身份认证组件
类库组件 .NET Core的身份认证使用的类库如下图:常用的 Microsoft.AspNetCore.Authorization Microsoft.AspNetCore.Authorizatio ...
- 增删改(DML)操作
增删改(DML)操作 1.1事务(transaction) 事务是数据库操作的最小单元,又ACID的特性,应该保证一个事务的sql语句要么同时成功,要么都不成功. Mybatis中配置了事务管理器,t ...
- Linux.超级管理员root-密码破解
Linux.超级管理员root-密码破解 环境: 我是在虚拟机中安装的Linux,然后进行破解的.实体机,应该也是可以的,但我没有尝试过.如果你有实体机,试试吧... 又不要钱~ 在系统启动的时候,会 ...
- Nodejs中原生遍历文件夹
最近在听老师讲的node课程,有个关于把异步变为同步读取文件夹的知识点做一些笔记, 让迭代器逐个自执行.
- LeetCode155.最小栈
设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- 删除栈顶的元素. top() -- 获取栈顶元素. ...
- 关于windows中80端口被占用
很奇怪,windows7系统中的80端口被pid 为4 的system进程监听. 尝试关闭IIS功能,并在这期间进行过多次重启,均无效. 后来依照这篇文件解决的:https://www.jianshu ...
- pip install pyinstaller
C:\Users\coder211\Desktop>pip install pyinstallerCollecting pyinstaller Downloading PyInstaller-3 ...