zoukankan      html  css  js  c++  java
  • hdu 1299 Diophantus of Alexandria

     1/x + 1/y = 1/n  1<=n<=10^9
    给你 n 求符合要求的x,y有多少对 x<=y
    // 首先 x>n 那么设 x=n+m 那么 1/y= 1/n - 1/(n+m)
    // 1/y = m/(n*n+n*m) 所以满足 n*n|m 的m都是可以的
    // 问题转化成求n*n 的约数个数 因数分解 然后用求约数个数公式
    // 最后答案记得 除 2 因为重复算了
    #include <iostream> #include <algorithm> #include <queue> #include <vector> #include <math.h> #include <stdio.h> #include <string.h> using namespace std; #define maxm 100010 // #define maxn 47010 #define LL __int64 int prim[47000],p; void getPrime(){ int maxn=sqrt(1000000001.0); int i,j; for(i=4;i<=maxn;i+=2) prim[i]=1; for(i=3;i*i<=maxn;i+=2) if(!prim[i]) for(j=i*i;j<=maxn;j+=i) prim[j]=1; for(i=2;i<=maxn;i++) if(!prim[i]) prim[p++]=i; } int main() { getPrime(); int n,T; LL ans; int i,ct,Case=1; scanf("%d",&T); while(T--){ scanf("%d",&n); i=0; ans=1; while(i<p){ if(n%prim[i]==0){ ct=0; while(n%prim[i]==0){ ct++; n=n/prim[i]; } ans=ans*(2*ct+1); } if(n==1) break; i++; } if(n!=1) ans=ans*3; printf("Scenario #%d: ",Case++); printf("%I64d ",(ans+1)/2); } return 0; }
  • 相关阅读:
    什么是序列化
    命令执行漏洞
    sql注入总结
    npm包之merge-descriptors
    Koa路由中间件之koa-router
    TypeScript声明文件(.d.ts)的使用
    TypeScript使用的简单记录
    TypeScript的安装、使用及配置
    Node websocket简单封装
    使用docker-compose配置mysql服务
  • 原文地址:https://www.cnblogs.com/372465774y/p/3214762.html
Copyright © 2011-2022 走看看