1 条题解
-
0
C :
#include "stdio.h" int main() { int i,s,n,sum,g; while(scanf("%d",&n)!=EOF && n<=100 && n>0) { sum=0; for(i=1;i<=n;i++) { if(i%7 && (i%10)!=7 && (i/10)!=7) sum=sum+i*i; } printf("%d\n",sum); } return 0; }
C++ :
#include<stdio.h> int main() {int i,k,n; while(scanf("%d",&n)!=EOF) {k=0; for(i=1;i<=n;i++) if(i!=7&&i!=17&&i!=27&&i!=37&&i!=47&&i!=57&&i!=67&&i!=77&&i!=87&&i!=97&&i!=70&&i!=71&&i!=72&&i!=73&&i!=74&&i!=75&&i!=76&&i!=78&&i!=79&&i!=14&&i!=21&&i!=28&&i!=35&&i!=42&&i!=49&&i!=56&&i!=63&&i!=84&&i!=91&&i!=98) k+=i*i; printf("%d\n",k); } return 0; }
Pascal :
var ans,i,n:longint; function yg(i:longint):boolean; var j:longint; m:string; begin if (i mod 7=0) then exit(true); str(i,m); for j:=1 to length(m) do if m[j]='7' then exit(true); exit(false); end; begin while not(eof) do begin ans:=0; readln(n); for i:=1 to n do if not(yg(i)) then ans:=ans+i*i; writeln(ans); end; end.
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int S=0; for(int i=1;i<=n;i++){ int flag=0; String s=String.valueOf(i); if(i%7==0){ flag=1; }else{ for(int j=0;j<s.length();j++){ if(s.substring(j, j+1).equals("7")){ flag=1; break; } } } if(0==flag){ S+=i*i; } } System.out.println(S); } sc.close(); } }
- 1
信息
- ID
- 1165
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者