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
1/4
1/1
1/5000
2
3
1
32

感谢大佬的思路: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;
}

 数论菜鸟瑟瑟发抖。

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 17:28
25届每天都在焦虑找工作的事情0offer情绪一直很低落硬撑着面了一个岗位岗位有应酬的成分面试的时候hr给我出各种场景题问的问题比较犀利&nbsp;有点压力面的感觉感觉有点回答不上来本来就压抑的情绪瞬间爆发了呢一瞬间特别想哭觉得自己特别没用没绷住掉眼泪了事后想想觉得自己挺有病的&nbsp;真的破大防了
喜欢唱跳rap小刺猬...:我觉得没关系吧,之前有一次面试leader给我压力面,我顶住了压力,结果入职的时候发现组里氛围很差,果断跑路。其实从面试就能大概看出组的情况,面试体验好的组倒是不一定好,但是面试体验不好的组。。。就很难说
面试尴尬现场
点赞 评论 收藏
分享
屌丝逆袭咸鱼计划:心态摆好,man,晚点找早点找到最后都是为了提升自己好进正职,努力提升自己才是最关键的😤难道说现在找不到找的太晚了就炸了可以鸡鸡了吗😤早实习晚实习不都是为了以后多积累,大四学长有的秋招进的也不妨碍有的春招进,人生就这样
点赞 评论 收藏
分享
来个大佬救一下,为上投了都是石沉大海了,没实习经历的话怕秋招直接进不了面。什么实习这么难找,基本
心态爆炸了:现在正式的岗位都少,实习基本不咋招的,除了大厂,中小企业其实没那么多岗位需求,就算是有,大多都是招一两个廉价劳动力,同时,他们也会希望你一来就能干活的,没时间培训你,就让你了解公司的项目,你了解完就可以开始干活。再者是,很多低质量的实习其实用处没有那么大的。我去年也是找实习找到破防,最后去了一家深圳的小公司实习,工作对我来说很简单,甚至不如我在学校做的项目,秋招的时候,这段实习经历也并没有帮上什么忙,投递简历,依旧非常低的回复率。低回复率是常态,尤其是找实习,找不到,那就把重心放在优化自己的简历和项目,多看八股文,锻炼自己的面试能力,多看别人的面经,自己模拟面试,等秋招的时候,只要有那么寥寥几次,好好抓住那几次机会。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务