首页 > 其他分享 >Gauss Prime UVA - 1415

Gauss Prime UVA - 1415

时间:2023-04-23 17:56:59浏览次数:39  
标签:Prime int ts Gauss UVA include 1415

 

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=5e4;
int b[N+2], pm[N+2],tot=0;

 void init(){
     b[1]=1;
     for(int i=2;i<=N;i++){
         if(b[i]) continue;
         pm[++tot]= i; 
         for(int j=2;j*i<=N;j++) b[j*i]=1;
     }
 }
 int chk(int a,int b){
     if(a==0) return 0 ;
     int num = a*a+ b*b*2;
     
     for(int i=1;i<=tot && pm[i]<num;i++)
         if(num%pm[i]==0) return 0;
     
     return 1;
 }
 signed main(){
     init() ;
      int ts;
       cin>>ts;
  while (ts--) {
    int a, b;
    cin>>a>>b;
    printf("%s\n",chk(a,b)?"Yes":"No");
  }
 }

 

标签:Prime,int,ts,Gauss,UVA,include,1415
From: https://www.cnblogs.com/towboa/p/17347286.html

相关文章

  • 【CMU15-445 FALL 2022】Project #0 - C++ Primer
    关于参考&鸣谢课程官网CMU15445vscode/clionclang12cmake环境配置C++调试窗口显示“forstringvariable【CMU15-445数据库】bustubProject#0:Trie树实现(C++Primer)2022CMU15-445学习群——152391370前言按照课程要求,本文并不会给出实现代码,可以当做是我遇到问题的总......
  • Counting Rectangles UVA - 10574
    给出n个点。问选出4个点作为定点,能够组成多少个平行与坐标轴的矩形。 点按照x排序 n^2挑选出垂直x轴的线段,按照y1排序  #include<iostream>#include<cstring>#include<algorithm>#include<vector>usingnamespacestd;constintN=1e5;structT{ intx......
  • Eigensequence UVA - 11133
    给你一个递增序列的第一位a1,最后一位an,求有多少个序列满足:以a1为首,an为尾 1、B(1)=A(1)2、后面每项满足A[j]=B[j], A(j-1)<B(j)≤A(j),且bj能整除A(j)-A(j-1)。   F[i][j]最后一位为j的方案数#include<iostream>#include<cstring>#include<a......
  • UVA Children’s Game(贪心)
    Description4thIIUCInter-University ProgrammingContest,2005AChildren’sGameInput:standardinputOutput:standardoutputProblemsetter: Md. KamruzzamanTherearelotsofnumbergamesforchildren.Thesegamesareprettyeasytoplaybutnotsoeasyt......
  • UVA Immediate Decodability(简单字典树)
    ImmediateDecodabilityTimeLimit:3000MS     MemoryLimit:0KB     64bitIOFormat:%lld&%lluSubmit StatusDescription  ImmediateDecodability Anencodingofasetofsymbolsissaidtobe immediately decodableifnocode......
  • UVA10237 Bishops
      #include<iostream>#include<cstring>#include<queue>usingnamespacestd;constintN=2e5+2;#defineintlonglongintn,m,f1[50][2000],f2[50][2000];voidsov(){ memset(f1,0,sizeoff1);memset(f2,0,sizeoff2); f1[0][0]=f2......
  • UVA How Many Points of Intersection?
      HowManyPointsofIntersection? a dotsonthetoprowand b dotsonthebottomrow.Wedrawlinesegmentsconnectingeverydotonthetoprowwitheverydotonthebottomrow.Thedotsarearrangedinsuchawaythatthenumberofinternalintersectio......
  • (UVA) The ? 1 ? 2 ? ... ? n = k problem
    The?1?2?...?n=kproblemTheproblemGiventhefollowingformula,onecansetoperators'+'or'-'insteadofeach'?',inordertoobtainagivenk?1?2?...?n=kForexample:toobtaink=12,theexp......
  • How Many O's? UVA - 11038
    写下区间[a,b]的所有数 ,问一共有多少个0 #include<iostream>#include<cstring>#include<vector>usingnamespacestd;#defineintlonglongintn,f[40][40][2][2];vector<int>a;intdfs(intx,intcnt0,intflg,intlead){ if(x<0){ i......
  • c++primer 16模板(参考B站阿西拜编程视频)
              以上还是要写一个函数,我们可以采用c++17的新语法:按条件编译,以此来作为条件:    若将特例化函数模板放在函数调用之前的话:调用compare(p1,p2)将有两个版本适合,采用特例化版本;调用compare("hi","mom")也将有两......