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, ...
随机推荐
- [sh]rm -rf*的防护和普通用户执行命令
尽量用普通用户执行,因为普通用户无法删除root的文件,避免误删除 rm -rf 不可取, 尽量find+rm -rf 尽量cd && rm -rf * 加上逻辑 cd /tmp/re ...
- iot平台在k8s搭建过程
统一在 cd /opt/iot nohup /opt/iopservices.sh >/var/log/helmapi.log & 直接查看pod日志? kubectl logs i ...
- es6 数组..... ==和===的区别 es6的递归方式 es6find函数 timer setTimeout v-html的用法,-
相当于push了 find函数来找到某个值 如果新建一个 setTimeout 的timer 首先得清除这个timer. v-html用法之一就是加载后台传过来的模板
- 背景图宽高100%无法无法显示的问题【body设置relative,当前元素absolute】
以下1,2两个关键元素 body{ width:100%; height:100%; position:relative; //1 } .login-form { width: 100%; ...
- 一个toolkit或者一个开源项目如何学习它并使用它
一个toolkit或者一个开源项目如何学习它并使用它 一般一个流行的toolkit和开源项目,一般都会被广泛地被应用: 那么,我们如何学习它,如何应用它在自己的业务场景中呢? 答案就是:学习源码并借鉴 ...
- nodejs+mysql入门实例(删)
//连接数据库 var mysql = require('mysql'); var connection = mysql.createConnection({ host: 'bdm253137448. ...
- 数据分析与挖掘 - R语言:KNN算法
一个简单的例子!环境:CentOS6.5Hadoop集群.Hive.R.RHive,具体安装及调试方法见博客内文档. KNN算法步骤:需对所有样本点(已知分类+未知分类)进行归一化处理.然后,对未知分 ...
- Makefile中变量定义中末尾不能有空格
我在Makefile中添加了 ifndef EMASSDIR EMASSDIR=$(shell emassTop.py)endif 但是emassTop.py)后面不小心加入了空格,造成出现“Make ...
- Ireport第一张web项目报表。
原先项目里面的统计分析报表都是和普通的系统页面一样开发的,SSM架构,从数据库一层一层往前面传数据,最后通过jsp表现出来,这次在领导的建议下使用IReport进行报表开发,果然还是要使用工具啊,社会 ...
- c#winform,知道图像路径,怎么在程序运行时往image里面添加图片
貌似可以直接添加啊 ,要改变显示的图片,就是将图片的路径赋值给picturebox即可pictureBox1.ImageLocation="图片路径"动态的改变这个值就行了.