zoukankan      html  css  js  c++  java
  • 完全平方数 (Square Numbers,UVa 11461)

     1 #include <iostream>
     2 #include <string.h>
     3 #include <string>
     4 #include <fstream>
     5 #include <algorithm>
     6 #include <stdio.h>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <cmath>
    11 using namespace std;
    12 const double eps = 1e-8;
    13 const int INF=0x7fffffff;
    14 unsigned long long uINF = ~0LL;
    15 #define MAXN 10000007
    16 typedef long long LL;
    17 LL vis[MAXN];
    18 LL prime[MAXN];
    19 
    20 void sieve(LL n)
    21 {
    22     LL m=(LL)sqrt(n+0.5);
    23     memset(vis,0,sizeof(vis));
    24     for(LL i=2;i<=m;i++)if(!vis[i])
    25     for(LL j=i*i;j<=n;j+=i)vis[j]=1;
    26 }
    27 
    28 LL gen_prime(LL n)
    29 {
    30     sieve(n);
    31     LL c=0;
    32     for(LL i=2;i<=n;i++)if(!vis[i])
    33         prime[c++]=i;
    34     return c;
    35 }
    36 
    37 LL gcd(LL a,LL b)
    38 {
    39     return b==0?a:gcd(b,a%b);
    40 }
    41 int num[100001];
    42 int main()
    43 {
    44     int a,b;
    45     int temp=1;
    46     memset(num,0,sizeof(num));
    47     for(LL i=1;i<100001;i++)
    48     {
    49         if(i==(LL)(temp*temp)){num[temp++]=i;}
    50         //cout<<num[i]<<endl;system("pause");
    51     }
    52     while(scanf("%d%d",&a,&b),a+b!=0)
    53     {
    54         int sa=sqrt(a);
    55         int sb=sqrt(b);
    56         //cout<<sa<<' '<<sb<<endl;
    57         int ans=sb-sa;
    58         if(a==num[sa])ans++;
    59         //if(b==num[sb])ans++;
    60         printf("%d
    ",ans);
    61     }
    62 
    63     return 0;
    64 }
     1 #include <iostream>
     2 #include <string.h>
     3 #include <string>
     4 #include <fstream>
     5 #include <algorithm>
     6 #include <stdio.h>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <cmath>
    11 using namespace std;
    12 const double eps = 1e-8;
    13 const int INF=0x7fffffff;
    14 unsigned long long uINF = ~0LL;
    15 #define MAXN 10000007
    16 typedef long long LL;
    17 LL vis[MAXN];
    18 LL prime[MAXN];
    19 
    20 void sieve(LL n)
    21 {
    22     LL m=(LL)sqrt(n+0.5);
    23     memset(vis,0,sizeof(vis));
    24     for(LL i=2;i<=m;i++)if(!vis[i])
    25     for(LL j=i*i;j<=n;j+=i)vis[j]=1;
    26 }
    27 
    28 LL gen_prime(LL n)
    29 {
    30     sieve(n);
    31     LL c=0;
    32     for(LL i=2;i<=n;i++)if(!vis[i])
    33         prime[c++]=i;
    34     return c;
    35 }
    36 
    37 LL gcd(LL a,LL b)
    38 {
    39     return b==0?a:gcd(b,a%b);
    40 }
    41 int num[100001];
    42 int main()
    43 {
    44     int a,b;
    45     int temp=1;
    46     memset(num,0,sizeof(num));
    47     for(LL i=1;i<100001;i++)
    48     {
    49         if(i==(LL)(temp*temp)){num[temp++]=i;}
    50         //cout<<num[i]<<endl;system("pause");
    51     }
    52     while(scanf("%d%d",&a,&b),a+b!=0)
    53     {
    54         int sa=sqrt(a);
    55         int sb=sqrt(b);
    56         //cout<<sa<<' '<<sb<<endl;
    57         int ans=sb-sa;
    58         if(a==num[sa])ans++;
    59         //if(b==num[sb])ans++;
    60         printf("%d
    ",ans);
    61     }
    62 
    63     return 0;
    64 }
  • 相关阅读:
    金融学专业排名
    学经济学专业排行榜
    国内,美国数学专业排名
    为什么国外程序员爱用苹果 Mac 电脑?
    计算机专业-世界大学学术排名,QS排名,U.S.NEWS排名
    基金合作伙伴
    融资晚报:一大波创业公司获得融资
    有哪些适合学生参与的 C++,网络编程方面的开源项目?
    SuperSocket内置的命令行协议的解析
    C# Socket 您的主机中的软件中止了一个已建立的连接 An established connection was aborted by the software in your host machine
  • 原文地址:https://www.cnblogs.com/TO-Asia/p/3208496.html
Copyright © 2011-2022 走看看