SDUT 3257 Cube Number 简单数学

把所有数的立方因子除去,那么一个数可以和它组成立方的数是确定的,统计就行

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const int N=1e6+5;
const int INF=0x3f3f3f3f;
int vis[N],prime[1005],cnt;
void getprime(){
  bool v[1020];
  memset(v,0,sizeof(v));
  for(int i=2;i*i<=1000;++i){
    if(v[i])continue;
    for(int j=i*i;j<=1000;j+=i)
      v[j]=1;
  }
  for(int i=2;i<=1000;++i)
    if(!v[i])prime[++cnt]=i;
}
int main(){
    int T,n;
    getprime();
    // printf("%d\n",cnt);
    scanf("%d",&T);
    while(T--){
      memset(vis,0,sizeof(vis));
      scanf("%d",&n);
      LL ans=0;
      for(int i=1;i<=n;++i){
        LL t,t1;scanf("%lld",&t),t1=t,t=1;
        LL aim=1;bool flag=0;
        for(int j=1;j<=cnt&&prime[j]<=t1/prime[j];++j){
            int tmp=0;
            while(t1%prime[j]==0)t1/=prime[j],++tmp;
            if(tmp%3==1){
              t*=prime[j];
              aim*=prime[j];
              if(aim>N-5)flag=1;
              aim*=prime[j];
              if(aim>N-5)flag=1;
            }
            else if(tmp%3==2){
              t*=prime[j]*prime[j];
              aim*=prime[j];
              if(aim>N-5)flag=1;
            }
        }
        if(!flag){
          if(t1>1){
            t*=t1;
            aim*=t1;
            if(aim>N-5)flag=1;
            aim*=t1;
            if(aim>N-5)flag=1;
          }
          if(!flag)ans+=vis[aim];
        }
        ++vis[t];
      }
      printf("%lld\n",ans);
    }
    return 0;
}

时间: 2024-10-11 21:51:53

SDUT 3257 Cube Number 简单数学的相关文章

SDUT 3258 Square Number 简单数学

和上一题一样,把平方因子除去,然后对应的数就变成固定的 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; typedef long long LL; const int N=1e6+5; const int INF=0x3f3f3f3f; int vis[N],prime[1005],cnt; void getp

HDU 1018 Big Number (简单数学)

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25649    Accepted Submission(s): 11635 Problem Description In many applications very large integers numbers are required. Some of these

计蒜客 31452 - Supreme Number - [简单数学][2018ICPC沈阳网络预赛K题]

题目链接:https://nanti.jisuanke.com/t/31452 A prime number (or a prime) is a natural number greater than $1$ that cannot be formed by multiplying two smaller natural numbers. Now lets define a number $N$ as the supreme number if and only if each number m

编译器--简单数学表达式计算器

做了一个能够计算简单数学表达式值的小计算器,算不上是编译器,但用到了编译器的知识.最近在看一些编译器的东西,所以动手写这个最简单的计算器,既是对那些抽象的编译器知识有个形象的认识,也为后面添加复杂的东西--语句打下基础.此计算器是以<编译原理与实践>中实现的tiny编译器为参考写的,tiny是一个值得去研究的编译器,可以说是麻雀虽小,五脏俱全.从词法分析到代码生成都有,并且代码非常清晰易懂.我觉得想要了解编译器,可以从tiny入手,去将它跑起来并分析.废话不多说,开始记录这个小计算器. 先说下

SGU - 123 - The sum (简单数学!)

SGU - 123 The sum Time Limit: 250MS   Memory Limit: 4096KB   64bit IO Format: %I64d & %I64u Submit Status Description Here is your second problem, keep calm and solve it . Nacci sequence of numbers is known to all : F1 = 1; F2 = 1; Fn+1 = Fn + Fn-1,

hdu 2200 Eddy&#39;s AC难题(简单数学。。)

题意: N个人,每个人AC的题数都不一样. Eddy想从中选出一部分人(或者全部)分成两组.必须满足第一组中的最小AC数大于第二组中的最大AC数. 问共有多少种不同的选择方案. 思路: 简单数学.. 代码: ll C(int n,int x){ ll ans=1; rep(i,1,x){ ans = ans*(n+1-i)/i; } return ans; } int main(){ int n; while(cin>>n){ ll ans = 0; rep(i,2,n){ ans += (C

hdu 4670 Cube number on a tree(点分治)

Cube number on a tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1628    Accepted Submission(s): 382 Problem Description The country Tom living in is famous for traveling. Every year, man

HDU 1005 Number Sequence (数学规律)

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 104190    Accepted Submission(s): 25232 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A

【龙书笔记】用Python实现一个简单数学表达式从中缀到后缀语法的翻译器(采用递归下降分析法)

上篇笔记介绍了语法分析相关的一些基础概念,本篇笔记根据龙书第2.5节的内容实现一个针对简单表达式的后缀式语法翻译器Demo. 备注:原书中的demo是java实例,我给出的将是逻辑一致的Python版本的实现. 在简单后缀翻译器代码实现之前,还需要介绍几个基本概念. 1. 自顶向下分析法(top-down parsing) 顾名思义,top-down分析法的思路是推导产生式时,以产生式开始符号作为root节点,从上至下依次构建其子节点,最终构造出语法分析树.在具体实现时,它会把输入字符串从左到右