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 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();
    scanf("%d",&T);
    while(T--){
      memset(vis,0,sizeof(vis));
      scanf("%d",&n);
      LL ans=0;
      for(int i=1;i<=n;++i){
        int t;scanf("%d",&t);
        for(int j=1;j<=cnt&&prime[j]<=t/prime[j];++j){
            int tmp=0;
            while(t%prime[j]==0)t/=prime[j],++tmp;
            if(tmp&1)t*=prime[j];
        }
        ans+=vis[t];
        // printf("%I64d\n",ans);
        ++vis[t];
      }
      printf("%lld\n",ans);
    }
    return 0;
}
 

时间: 2024-10-11 01:51:00

SDUT 3258 Square Number 简单数学的相关文章

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 v

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

Codeforces 828B Black Square(简单题)

Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n?×?m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum pos

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

做了一个能够计算简单数学表达式值的小计算器,算不上是编译器,但用到了编译器的知识.最近在看一些编译器的东西,所以动手写这个最简单的计算器,既是对那些抽象的编译器知识有个形象的认识,也为后面添加复杂的东西--语句打下基础.此计算器是以<编译原理与实践>中实现的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 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

山东省第六届“浪潮杯”ACM程序设计大赛:D:Square Number

Description: In mathematics, a square number is an integer that is the square of an integer. In other words, it is the product of some integer with itself. For example, 9 is a square number, since it can be written as 3 * 3. Given an array of distinc