打表找规律:
#include<stdio.h> #include<math.h> #define N 250 bool judge(int i,int j) { for(int k=2;k<j;k++) if(i%k==0&&j%k==0)return true; return false; } int a[N]; int main() { int i,j; int ans=0; for(i=1;i<N;i++) { printf("输入:%d",i); for(j=2;j<i;j++) { if(i%j&&judge(i,j)) a[i]++; } //if(a[i]&&1) printf(" f(x)=%d",a[i]); //else printf("0 "); if(a[i]&1)ans++; printf(" 值%d",ans); printf(" 处理%d ",i/2); } return 0; }
用G++提交能过,C++提交过不了
#include<stdio.h> #include<math.h> #define ll long long int main() { int _case; long long x,y; scanf("%d",&_case); while(_case--) { scanf("%I64d %I64d",&x,&y); long long x1,y1; x--; if(x>1) { x1=x/2; long long x2=sqrt(x); if(x2&1)x1-=1; else x1-=2; } else x1=0; if(y!=1) { y1=y/2; long long y2=sqrt(y); if(y2&1)y1-=1; else y1-=2; } else y1=0; printf("%I64d ",y1-x1); } return 0; }