1 solutions
-
0
C++ :
#include<iostream> #include<string> using namespace std; int mod7(string s){ int sum=0; for(int i=0;i<s.size();i++){ sum=(sum*10+(s[i]-'0'))%7; } if(sum%7==0) return 1; else return 0; } int main() { int t; string s; while(cin>>s){ if(mod7(s)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }Pascal :
const b:array[1..6]of longint=(1,3,2,-1,-3,-2); var st:string; a:array[0..110]of longint; i,j,n,s:longint; begin while not eof do begin readln(st); s:=0; if st<>'' then begin for i:= 1 to length(st) do val(st[i],a[i]); j:=1; for i:= length(st) downto 1 do begin s:=s+b[j]*a[i]; if j=6 then j:=1 else j:=j+1; end; if s mod 7=0 then writeln('YES') else writeln('NO'); end; end; end.
- 1
Information
- ID
- 18442
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By