题目链接:http://lightoj.com/volume_showproblem.php?problem=1220

题意:已知 x=b中的 x 求最大的 p,其中 x b p 都为整数

x = (p1a1*p2a2*p3a3*...*pkak), pi为素数;则结果就是gcd(a1, a2, a3,...,ak);

当x为负数时,要把ans缩小为奇数;

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef long long LL;
const int oo = 0xfffffff;
const int N = 1e6+;
const double eps = 1e-; int f[N], p[N], k = ;
void Init()
{
for(int i=; i<N; i++)
{
if(!f[i]) p[k++] = i;
for(int j=i; j<N; j+=i)
f[i] = ;
}
} int gcd(int a, int b)
{
return b == ? a : gcd(b, a%b);
} int cnt[N]; int main()
{
Init(); int T, t = ; scanf("%d", &T); while(T--)
{
LL n;
int flag = ; scanf("%lld", &n); if(n < )
{
n = -n;
flag = ;
} int ans = ; memset(cnt, , sizeof(cnt)); for(int i=; i<k && (LL)p[i]*p[i]<=n; i++)
{
while(n%p[i] == )
{
cnt[i]++;
n /= p[i];
}
if(ans == && cnt[i])
ans = cnt[i];
else if(cnt[i])
ans = gcd(cnt[i], ans);
} if(n > || ans == )
ans = ; if(flag)///负数,结果一定是奇数;
{
while(ans% == )
ans /= ;
}
printf("Case %d: %d\n", t++, ans);
}
return ;
}
/*
-1000000
1 3
1
*/

LightOj 1220 - Mysterious Bacteria (分解质因子x=b^p 中的 x 求最大的 p)的更多相关文章

  1. LightOJ 1220 Mysterious Bacteria(唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1220 Mysterious Bacteria Time Limit:500MS     Memo ...

  2. LightOj 1220 Mysterious Bacteria

    题目大意: 给出一个x,求满足x = b^p,p最大是多少? 解题思路: x可以表示为:x = p1^e1 * p2^e2 * p3^e3 ....... * pn^en. p = gcd (e1,e ...

  3. LightOJ 1220 Mysterious Bacteria 水题

    暴力就行了,找出素因子,正的最多是30,然后负的最多是31(这一点wa了一次) #include <cstdio> #include <iostream> #include & ...

  4. UVA 10780 Again Prime? No Time. 分解质因子

    The problem statement is very easy. Given a number n you have to determine the largest power of m,no ...

  5. HDU 4497 GCD and LCM(分解质因子+排列组合)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 题意:已知GCD(x, y, z) = G,LCM(x, y, z) = L.告诉你G.L,求满 ...

  6. hdu6237 分解质因子

    题意:给一堆石子,每次移动一颗到另一堆,要求最小次数使得,所有石子数gcd>1 题解:枚举所有质因子,然后找次数最小的那一个,统计次数时,我们可以事先记录下每堆石子余质因子 的和,对所有石子取余 ...

  7. NYOJ-476谁是英雄,分解质因子求约数个数!

    谁是英雄 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 十个数学家(编号0-9)乘气球飞行在太平洋上空.当横越赤道时,他们决定庆祝一下这一壮举.于是他们开了一瓶香槟.不 ...

  8. Codeforces Round #828 (Div. 3) E2. Divisible Numbers (分解质因子,dfs判断x,y)

    题目链接 题目大意 给定a,b,c,d四个数,其中a<c,b<c,现在让你寻找一对数(x,y),满足一下条件: 1. a<x<c,b<y<d 2. (x*y)%(a ...

  9. HDU 4135 Co-prime (容斥+分解质因子)

    <题目链接> 题目大意: 给定区间[A,B](1 <= A <= B <= 10 15)和N(1 <=N <= 10 9),求出该区间中与N互质的数的个数. ...

随机推荐

  1. ggplot2包--R可视化

    1.ggplot2发展历程 ggplot2是Hadley在爱荷华州立大学博士期间的作品,也是他博士论文的主题之一,实际上ggplot2还有个前身ggplot,但后来废弃了,某种程度上这也是Hadley ...

  2. Uva401Palindromes

      Palindromes  A regular palindrome is a string of numbers or letters that is the same forward as ba ...

  3. mac mysql

    http://blog.neten.de/posts/2014/01/27/install-mysql-using-homebrew/

  4. 【原】iOS学习39网络之数据请求

    1. HTTP和HTTPS协议 1> URL URL全称是Uniform Resource Locator(统一资源定位符)通过1个URL,能找到互联网上唯一的1个资源 URL就是资源的地址.位 ...

  5. leetcode Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  6. 当编译CCBReader时出现 “ CCBAnimationManager.m Use of undeclared identifier 'other‘ ” 解决方法

    第一种解决方法是去github上下载最新的CCBReader 第二种解决方法是把other替换成self.inner 建议用新版本的

  7. Windows Phone Foreground Toast

    Basically ToastPrompt is an UI component that derives from the Coding4Fun toolkit's abstract PopUp&l ...

  8. Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

    What it is saying is, it found the DLL, but it couldn't find a type named "namespace.User" ...

  9. 存储过程: 存储过程(stored procedure)有时也称为sproc。存储过程存储于数据库中而不是在单独的文件中,有输入参数、输出参数以及返回值等。

    存储过程示例一: 执行存储过程方法一: 执行存储过程方法二: 存储过程可以定义返回值: 修改存储过程: 利用存储过程查找三个表内的信息: 练习:  超市管理系统:表一:门店仓库表   MenDian ...

  10. android-Activity(四大组件之一)

    一.Activity理解 1.定义: 直译为活动,是Android定义四大应用组件之一,也是最重要的用的最多的: 用来提供一个能让用户操作并与之交互的界面 一个应用有多个界面也就是包含多个Activi ...