思路:

这题有个结论也可以自己归纳:

对于给定的n,其约数用pi表示

T(n)=T(p1)T(p2)……T(pn)T(n')

其中T(n')是这个式子所独有的也就是

T(n')=(x^n-1)/T(p1)/T(p2)……/T(pn)

代码如下:

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#define MAX 1102
using namespace std;
struct pol
{
int bit[MAX],len;
void init(){memset(bit,,sizeof(bit));len=;}
}p[MAX];
int ans[MAX];
int com(pol a,pol b)
{
if(a.len!=b.len)return a.len-b.len;
for(int i=a.len-;i>=;i--)
if(a.bit[i]!=b.bit[i]){
if(abs(a.bit[i])!=abs(b.bit[i]))
return abs(a.bit[i])-abs(b.bit[i]);
return a.bit[i]-b.bit[i];
}
return ;
}
bool cmp(int a,int b)
{
return com(p[a],p[b])<;
}
void shows(int n)
{
if(n>) printf("x^%d",n);
else if(n==) printf("x");
}
void show(pol a)
{
int x;
printf("(");
for(int i=a.len-;i>=;i--){
if(a.bit[i]==) continue;
if(i==){
if(a.bit[i]>) printf("+%d",a.bit[i]);
else printf("%d",a.bit[i]);
continue;
}
if(i==a.len-){
if(a.bit[i]<) printf("-");
x=abs(a.bit[i]);
if(x>) printf("%d",x);
shows(i);
continue;
}
if(a.bit[i]<) printf("-");
else printf("+");
x=abs(a.bit[i]);
if(x>) printf("%d",x);
shows(i);
}
printf(")");
}
pol Div(pol a,pol b)
{
pol c;
c.init();
for(int i=a.len-;i>=;i--)
if(a.bit[i]){
c.bit[i-b.len+]=a.bit[i];
int cnt=,cur=a.bit[i];
for(int j=b.len-;j>=;j--){
a.bit[i-cnt]-=cur*b.bit[j];
cnt++;
}
}
c.len=a.len;
while(c.len>&&c.bit[c.len-]==) c.len--;
return c;
}
int main(){
p[].bit[]=-;
p[].bit[]=;
p[].len=;
for(int i=;i<MAX;i++){
p[i].init();
p[i].bit[i]=;p[i].bit[]=-;
p[i].len=i+;
p[i]=Div(p[i],p[]);
for(int j=;j*j<=i;j++){
if(i%j==){
p[i]=Div(p[i],p[j]);
if(j*j!=i) p[i]=Div(p[i],p[i/j]);
}
}
}
int n,m;
while(scanf("%d",&n)&&n){
if(n==){
puts("x-1");
continue;
}
m=;
for(int i=;i*i<=n;i++){
if(n%i==){
ans[m++]=i;
if(i*i!=n) ans[m++]=n/i;
}
}
sort(ans,ans+m,cmp);
for(int i=;i<m;i++)
show(p[ans[i]]);
printf("\n");
}
return ;
}

hdu 4447 Yuanfang, What Do You Think?的更多相关文章

  1. HDU P4578 Transformation

    Problem Description Yuanfang is puzzled with the question below: There are n integers, a1, a2, …, an ...

  2. hdu 4578 线段树(标记处理)

    Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) ...

  3. HDU 4578 - Transformation - [加强版线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 Problem Description Yuanfang is puzzled with the ...

  4. HDU 4578 线段树玄学算法?

    Transformation 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4578 Problem Description Yuanfang is p ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. 3月3日(4) Remove Duplicates from Sorted List

    原题 Remove Duplicates from Sorted List 有序单链表去重,delete 只能对指针起作用. /** * Definition for singly-linked li ...

  2. 理解 pkg-config 工具

    引用了别人的文章:http://www.chenjunlu.com/2011/03/understanding-pkg-config-tool/ 你在 Unix 或 Linux 下开发过软件吗?写完一 ...

  3. Vim复制粘贴

    用了快一年Vim了,今天想要将vim里的一句话复制到浏览器里,结果捣鼓了半天.汗! 解决方案: 在vim中按“V”进入可视模式,选中要复制的文字 接下来要按3个键“+y(引号.加号.字母y),这样要复 ...

  4. linux前景到底怎么样啊?

    我就不长篇大论,举四个例子你看看. 1.目下最热最潮最流行的云计算技术的背后是虚拟化和网格技术,而虚拟化和网格技术基本是Linux的天下,目前虚拟化的三大家:Vmware,Xen,Hyper-V中,市 ...

  5. php进行多个数组合并zip

    $a = array_zip(array("Dog","Cat","Horse"), array(1,2,3), array("l ...

  6. 如何取消FLEX里模态窗口的毛玻璃效果

    在Flex里面,比如使用PopUpManager.createPopUp(this,TipWindow,false)第三个参数设成true 会出现毛玻璃效果让CPU飙升,可不可以改变模态窗口的效果,不 ...

  7. MySQL 5.6.26源码安装

    5.6.26源码安装包:http://pan.baidu.com/s/1kUl44WRcmake安装包链接:http://pan.baidu.com/s/1c0LuwJA 操作系统版本:CentOS ...

  8. 解决This system is not registered with RHN

    Redhat之所以会出现这个错误是因为没有注册RHN,我们只需要更新一下yum的源就可以了.使用命令 cd /etc/yum.repos.d/   进入yum的配置目录. 在终端中输入 wget ht ...

  9. ORA-15221: ASM operation requires compatible.asm of 11.2.0.0.0 or higher

    昨天在做存储迁移的时候,对ASM磁盘组的东西进行操作时,出现了如标题的错误.经查资料,发现原因如下:     如磁盘组是使用asmca图形化工具创建,则compatible.asm默认设置就已经为11 ...

  10. 深入PHP EOF(heredoc)用法详解

    介绍下使用EOF heredoc方式,输出长段内容的方法, <?php $name = '姓名'; print <<<EOT <html> <head> ...