1 / 9

1026: 【 入门 】 求满足条件的整数个数 在 1 - n 中,找出能同时满足用 3 除余 2 ,用 5 除余 3 ,用 7 除余 2 的所有整数的个数 , 如果没有请输出 0 。

1026: 【 入门 】 求满足条件的整数个数 在 1 - n 中,找出能同时满足用 3 除余 2 ,用 5 除余 3 ,用 7 除余 2 的所有整数的个数 , 如果没有请输出 0 。 输入一行,只有一个整数 n(1<=n<=2000) 输出只有一行(这意味着末尾有一个回车符号),包括 1 个整数。 样例输入 10 样例输出 0. 穷举的思路. 循环变量 i. 从 1 到 n 范围. for i:=1 to n do. 1026: 【 入门 】 求满足条件的整数个数

Télécharger la présentation

1026: 【 入门 】 求满足条件的整数个数 在 1 - n 中,找出能同时满足用 3 除余 2 ,用 5 除余 3 ,用 7 除余 2 的所有整数的个数 , 如果没有请输出 0 。

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 1026: 【入门】求满足条件的整数个数 在1-n中,找出能同时满足用3除余2,用5除余3,用7除余2的所有整数的个数,如果没有请输出0。 输入一行,只有一个整数n(1<=n<=2000) 输出只有一行(这意味着末尾有一个回车符号),包括1个整数。 样例输入 10 样例输出 0 穷举的思路 循环变量i 从1到n 范围 for i:=1 to n do

  2. 1026: 【入门】求满足条件的整数个数 在1-n中,找出能同时满足用3除余2,用5除余3,用7除余2的所有整数的个数,如果没有请输出0。 输入一行,只有一个整数n(1<=n<=2000) 输出只有一行(这意味着末尾有一个回车符号),包括1个整数。 样例输入 10 样例输出 0 program ex1026; var i,n,s:integer; begin readln(n); s:=0; for i:=1 to n do if (i mod 3=2) and (i mod 5=3) and (i mod 7=2) then inc(s); writeln(s); end.

  3. 1032: 【入门】编程求阿姆斯特朗数 阿姆斯特朗数:如果一个三位正整数等于其各个数字的立方和,则该数称为阿姆斯特朗数,如407=4^3+7^3+0^3,试编程求出N以内的所有阿姆斯特朗数的个数。(100<=N<=999) 输入 输入一行,只有一个整数N 输出 输出只有一行(这意味着末尾有一个回车符号),包括1个整数。 样例输入 999 样例输出 4 100--999 穷举 循环体要做的事情 拆---判断

  4. 1037: 【入门】判断素数 题目描述 任意输入一个整数,判断它是否为素数。是的话输出"T",不是的话输出"F". 输入只有一行,包括1个整数(在长整型范围内)。 输出只有一行. 样例输入 57 样例输出 F 8 15 for i:=2 to n-1 do if n mod i=0 then writeln(‘F’) else writeln(‘T’);

  5. 猜一猜我是否是素数? n 先假设你是 pd:=true 9 …… N-1 2 3 4 素数得通过所有的测试 一旦测试过程中发现有约束就立刻pd:=false同时结束循环

  6. 8 10 长整型范围内 longint-2147483648..2147483647  program ex1037; var n,i:longint; pd:boolean; begin readln(n); pd:=true; for i:=2 to n-1 do if n mod i=0 then begin pd:=false; break; end; if n=1 then pd:=false; if pd=true then writeln('t') else writeln('f'); end.

  7. 2 18 3 12 4 9 36 trunc(sqrt(n))

  8. 长整型范围内 longint-2147483648..2147483647  program ex1037; var n,i:longint; pd:boolean; begin readln(n); pd:=true; for i:=2 to trunc(sqrt(n)) do if n mod i=0 then begin pd:=false; break; end; if n=1 then pd:=false; if pd=true then writeln('t') else writeln('f'); end. continue

  9. 1035: 【入门】素数的个数 题目描述 编程求正整数M与N之间的所有素数的个数.(M<=N) 输入只有一行,包括2个整数M,N,之间用一个空格分开。 输出只有一行(这意味着末尾有一个回车符号),包括1个整数。 样例输入 1 20 样例输出 8 思考

More Related