http://lightoj.com/volume_showproblem.php?problem=1220

题目大意: 给你一个x,求出满足 x=b^p, p最大是几。

分析:x=p1^a1*p2^a2*...*pn^an;

p最大是gcd(a1,a2,...,an)。

///他该诉你x,b,p都是整数,所以x,b有可能是负数。当x是负数时,p不能是偶数。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue> using namespace std;
typedef long long LL;
#define N 100000
#define ESP 1e-8
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a)) LL prime[N], k;
bool vis[N]; void Prime()
{
memset(vis, false);
k = ;
for(int i=; i<N; i++)
{
if(vis[i] == )
{
prime[k ++] = i;
for(int j=i+i; j<N; j+=i)
{
vis[j] = ;
}
}
}
} LL gcd(LL a, LL b)
{
LL r;
while(b)
{
r = a%b;
a = b;
b = r;
}
return a;
} LL solve(LL n)
{
LL ans, sum;
ans = ;
sum = ;
int flag = ; for(int i=; prime[i]*prime[i] <= n; i++)
{
if(n%prime[i] == )
{
ans = ;
while(n%prime[i] == )
{
n /= prime[i];
ans ++;
}
if(flag == )
{
sum = ans;
flag = ;
}
else if(flag == )
sum = gcd(sum, ans);
}
}
if(n>)
sum = ; return sum;
} int main()
{
int T, t=;
Prime();
scanf("%d", &T);
while(T --)
{
LL n;
scanf("%lld", &n); int b = ; if(n<)
{
n = -n;
b = ;
} LL sum = solve(n); if(b == && sum% == )
{
while(sum% == )
sum/=;
}
printf("Case %d: %lld\n", t++, sum);
}
return ;
}

1220 - Mysterious Bacteria--LightOj1220 (gcd)的更多相关文章

  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=b^p 中的 x 求最大的 p)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1220 题意:已知 x=bp 中的 x 求最大的 p,其中 x b p 都为整数 x = ...

  3. LightOj 1220 Mysterious Bacteria

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

  4. LightOJ 1220 Mysterious Bacteria 水题

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

  5. LightOJ-1220 Mysterious Bacteria 唯一分解定理 带条件的最大公因数

    题目链接:https://cn.vjudge.net/problem/LightOJ-1220 题意 给x=y^p,问p最大多少 注意x可能负数 思路 唯一分解定理,求各素因数指数的GCD 注意负数的 ...

  6. Mysterious Bacteria LightOJ - 1220

    题意: 给出一个数x 求 x = bp  的p的最大值 解析: 算术基本定理 分解质因数 任何一个数x都可以表示为  x == p1a1   *  p2a2  *  ````` * pnan 即  b ...

  7. LightOJ1220 —— 质因数分解

    题目链接:https://vjudge.net/problem/LightOJ-1220 1220 - Mysterious Bacteria    PDF (English) Statistics ...

  8. LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria

    题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...

  9. [kuangbin带你飞]专题十四 数论基础

            ID Origin Title   111 / 423 Problem A LightOJ 1370 Bi-shoe and Phi-shoe   21 / 74 Problem B ...

随机推荐

  1. iOS开发中获取文本的宽高的方式

    /** 计算单行文字的size @parms  文本 @parms  字体 @return  字体的CGSize */ + (CGSize)sizeWithText:(NSString *)text ...

  2. jquery ajax get /post

    $.get(URL,callback); $("button").click(function(){ $.get("demo_test.asp",functio ...

  3. 安装Eclipse及相关Plugin

    Eclipse: 此处选用基于Eclipse的开发工具:STS 官方网站:https://spring.io/tools/sts Plugins: Open Explorer文件浏览插件it open ...

  4. 修改server 2008远程桌面端口

    在“开始”-"运行"菜单里,输入regedit HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Serve ...

  5. Python 监控nginx服务是否正常

    Python 监控nginx服务是否正常 #!/usr/bin/env python import os, sys, time from time import strftime while True ...

  6. Python执行系统命令的方法 os.system(),os.popen(),commands

    os.popen():用python执行shell的命令,并且返回了结果,括号中是写shell命令 Python执行系统命令的方法: https://my.oschina.net/renwofei42 ...

  7. nullcon HackIM 2016 -- Crypto Question 2

    Some one was here, some one had breached the security and had infiltrated here. All the evidences ar ...

  8. excel中的TEXT函数

    TEXT 函数可将数值转换为文本,并可使用户通过使用特殊格式字符串来指定显示格式. TEXT(value, format_text) value  必需.数值.计算结果为数值的公式,或对包含数值的单元 ...

  9. wcf用svcutil导出泛型的元数据

    D:\aaa>svcutil net.tcp://192.168.1.110:44444/TradingsService.svc/mex /ct:System.Collections.Gener ...

  10. Linux基础-常用命令

    常用的压缩命令 一.tar 1.压缩:tar zcvf [压缩包名].tar.gz [待压缩的文件名 ... ] 2.解压缩:tar zxvf [压缩包名].tar.gz -C [指定的解压目录] 3 ...