1 条题解
-
0
C :
#include <stdio.h> int pn[4]={6,28,496,8128}; int main(){ int n,a,b,i,count; while(scanf("%d",&n)!=EOF){ while(n--){ count=0; scanf("%d %d",&a,&b); if(a>b) a^=b^=a^=b;//这是交换两个数的最短代码了吧... for(i=0;i<4;i++){ if(a<=pn[i]&&pn[i]<=b) count++; } printf("%d\n",count); } } return 0; }
C++ :
#include<stdio.h> #include<time.h> #include<stdlib.h> int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n,x,y,temp,z,count=0; scanf("%d",&n); while(n--) { scanf("%d%d",&x,&y); for(int a=x; a<=y; a++) { z=0; for(int b=1; b<a; b++) { if(a%b==0) z+=b; } if(z==a) count++; } printf("%d\n",count); count=0; } }
Java :
import java.util.Scanner; class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner reader=new Scanner(System.in); WanShu wan=new WanShu(); int T=reader.nextInt(); for(int i=0;i<T;i++){ int k=0; int first=reader.nextInt(); int second=reader.nextInt(); for(int j=first;j<=second;j++){ if(wan.abc(j)){ k=k+1; } } System.out.println(k); } } } class WanShu{ boolean abc(int a){ int s=0; for(int i=1;i<a;i++){ if(a%i==0) s=s+i; } if(s==a) return true; else return false; } }
- 1
信息
- ID
- 1331
- 时间
- 2000ms
- 内存
- 2048MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者