log in
About and Contact
© 2020 DOUBTCOOL
Python Code
n=input() a=[] c=0 l=len(n) val=0 for i in range(l): a.append(n[0:i+1]) for j in range(l): val=str(val) val=a[j] if(int(val)%(l-j)==0): c+=1 if(c==l): print("Yes") else: print("No")
what is wrong with my code can anybody help plzz?
#include <iostream> using namespace std; int main() { int n; cin>>n; int val=0,count=0; while(n!=0) { count++; val=n%count; cout<<count<<" "<<val<<" "<<n<<'\n'; if(val!=0) { cout<<"NO"; break; } n=n/10; } if(n==0) cout<<"YES"; // your code goes here return 0; }
HI VISHAL MISHRA, i tried executing your code ,
it show output for the input
input:
652281
output:
1 0 652281
2 0 65228
3 0 6522
4 0 652
5 0 65
6 0 6
YES
Actually you see the first column of output , its in wrong
order,
it should be like
6 0 652281
5 0 65228
4 0 6522
3 0 652
2 0 65
1 0 6
YES
and the third column should be divisible by first column.
if all are divisible , then you can print "yes" or its "NO
showing WA
#include <iostream> #include<vector> #include <list> #include <stack> #include<queue> #include <map> #include <set> #include<algorithm> #include<iomanip> #include <math.h> #include <stdio.h> #include<string.h> #include <stdlib.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define mod 1000000007 #define int long long #define w(t) int t; cin>>t; while(t--) int countDigit(int n) { int count = 0; while (n != 0) { n = n / 10; ++count; } return count; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, Number = 0, remainder,l; int flag,k; cin >> n; while (n != 0) { remainder = n % 10; Number = Number * 10 + (remainder - 2); n /= 10; } l = countDigit(Number); flag = 1; for (int i = 0; i <= l; i++) { k = Number % 10; if (k % (l - i + 1) != 0) { flag = 0; cout << "No"; break; } Number = Number / 10; } if (flag == 1) { cout << "Yes"; } return 0; }
Hi Vishal Mishra , i have updated your code , maybe this will work ,
check it out
#include <iostream> using namespace std; int main() { int n,c=0; cin>>n; int val=0,count=0; while(n!=0) { count++; if(n%count==0) { c++; } //cout<<count<<" "<<val<<" "<<n<<'\n'; n=n/10; } if(count==c) cout<<"Yes"<<endl; else cout<<"No"<<endl; // your code goes here return 0; }
what is wrong with this code?
int main() {
int n;
cin>>n;
int l=0;
while(n){
l++;
n=n/10;
}
//cout<<l<<endl;
int k=l;
for(int i=1;i<=l;i++){
int temp=n/pow(10,k-1);
if(temp%(l-i+1)!=0){
cout<<"No"<<endl;
break;
}
k--;
}
cout<<"Yes"<<endl;
return 0;
}
hi
but the question says that it should be divisible by (l - i + 1)
can you plzz compare MY code with ABHISHEK RAO'S code and tell me what is the difference because
his code got AC mark .